Sunday, March 24, 2019

Moq Sample:

Class to be unit tested:

public class A
{
    B _objectB;
    C _objectC;

    public A(B objectB, C objectC)
    {
        _objectB = objectB;
        _objectC = objectC;
    }
    public virtual int Operation(int number1, int number2)
    {
        int result = 0;

        result += _objectB.Multiply(number1, number2);
        result += _objectC.Divide(number1, number2);

        return result;
    }
}

Unit testing with mocking:

using Moq;
using Xunit;

public class ATest
{
    [Fact]
    public void Operation_MockDependencies_ShouldPass()
    {
        //Arrange
        Mock mockB = new Mock();
        Mock mockC = new Mock();
        var sut = new A(mockB.Object, mockC.Object);
        int number1 = 10;
        int number2 = 5;

        mockB.Setup(x => x.Multiply(number1, number2)).Returns(10);
        mockC.Setup(x => x.Divide(number1, number2)).Returns(25);

        //Act
        var result = sut.Operation(number1, number2);

        //Assert
        Assert.Equal(35, result);
    }
}

What is Moq


  • Moq is a mocking framework for .NET
  • Pronounce as “Mock-you” or “Mock”
  • It helps to isolate dependencies in unit testing
  • Nuget packages
  • Moq (4.10.1)
  • Reference: https://github.com/moq/moq4


xUnit sample

Class to be unit tested:

public class A
{
    B _objectB;
    C _objectC;

    public A(B objectB, C objectC)
    {
        _objectB = objectB;
        _objectC = objectC;
    }
    public virtual int Operation(int number1, int number2)
    {
        int result = 0;

        result += _objectB.Multiply(number1, number2);
        result += _objectC.Divide(number1, number2);

        return result;
    }
}

Unit test:

using Xunit;
public class ATest
{
    [Fact]
    public void Operation_WithCorrectParameters_ShouldPass()
    {
        //Arrange
        int number1 = 10;
        int number2 = 5;
        var sut = new A(new B(), new C());

        //Act
        var result = sut.Operation(number1, number2);

        //Assert
        Assert.Equal(52, result);
    }

}

What is xUnit


  • xUnit is unit testing tool for .NET framework
  • It is free & Open Source (Licensed under Apache)
  • Supports .NET core
  • Nuget packages
  • xunit (2.4.1)
  • Xunit.runner.visualstudio (2.4.1)
  • Reference: https://xunit.github.io/


Sunday, November 25, 2018

Fault domain and update domain with Azure

Both are availability settings.
It ensures availability of virtual machines during unforeseen situations or during upgrades.

Fault domain:

  • Fault domain is racks of computers.
  • Set of hardware components that share a single point of failure
  • In a data center, rack of computers can be fault domain, which might be sharing same power source or network connection
  • To minimize impact of possible hardware failure, Microsoft Azure deploys instances to at least 2 or more fault domains

Update domain:
  • Upgrade domain keep your application running during upgrades
  • Take down instances one by one, so that at any given time at least one running instance serving request
  • There will be 5 upgrade domains by default, it can increase up to 21

Conclusion
  • Fault domain - for unplanned failures
  • Update domain - for planned maintenance operations

References:

Sunday, September 23, 2018

Introduction to Microst Azure Cloud Services

Prerequisites:


Getting started:

  1. VS 2015 (Enterprise)  > New Project > Microsoft Azure Cloud Services
  2. Select ASP.NET Web Role 
  3. Select "MVC" as template

Microsoft Azure Compute Emulator:
It helps to test Azure Cloud Services locally


Types of Web Role:
  1.  ASP.NET Web Role  (service with a web user interface)
  2.  WCF Service Web Role (web role for WCF Service)
  3.  Worker Role (background processing Service)
  4.  Worker Role with service Bus Queue

Difference between Cloud Service and Web Role:
  • Cloud service is a container or a boundary or a box, which can put different services.
  • We can add different web role into a cloud service

Reference:

Monday, September 10, 2018

Kanban


  • Kanban is a Japanese word which means signboard/billboard (Kan = Visual, ban=board)
  • Kanban was widely used in manufacturing
  • It is first introduced in mid 20th Centuary in Toyota production system (Taiichi Ohno)


Advantage of using Kanban

  • Improve quality in work
  • Reduction of wasted effort
  • Faster turnaround
  • Identification & Elimination of bottlenecks
  • Improved teamwork

Kanban Board or Iteration Board
  • Backlog (New)
  • Active
  • Closed