public void BusinessController_Add_ShouldReturnTheAddedEntity()
        {
            // Arrange
            var expected = new BusinessEntity();
            var repoMock = new Mock <IBusinessEntityService>();

            repoMock.Setup(repo => repo.Store(It.IsAny <BusinessEntity>())).Returns(1664);
            repoMock.Setup(repo => repo.Get(1664)).Returns(expected);
            var sut = new BusinessController(repoMock.Object);

            // Act
            var actual = sut.Add(new BusinessEntity());

            // Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public void AutoFixture_ShouldBeAbleToAutoMock_DirectDependencies_WithNSubstitute(
            // Autofixture instanciates these for us
            [Frozen] IBusinessEntityService service,
            BusinessController sut,
            // this entity will have properties set with dummy values
            BusinessEntity expected)
        {
            // Arrange
            var entity = new BusinessEntity();

            service.Store(entity).Returns(expected.Id);
            service.Get(expected.Id).Returns(expected);

            // Act
            var actual = sut.Add(entity);

            // Assert
            actual.Should().Be(expected);
            service.Received(1).Store(entity);
            service.Received(1).Get(expected.Id);
        }
        public void BusinessControllerAdd_ShouldStoreEntityUsingIBusinessEntityService()
        {
            // Arrange
            var service     = Substitute.For <IBusinessEntityService>();
            var sut         = new BusinessController(service);
            var entityToAdd = new BusinessEntity();
            var expected    = new BusinessEntity {
                Id = 1664
            };

            // Setup mocks
            service.Store(entityToAdd).Returns(expected.Id);
            service.Get(expected.Id).Returns(expected);

            // Act
            var actual = sut.Add(entityToAdd);

            // Assert
            actual.Should().Be(expected);
            service.Received(1).Store(entityToAdd);
            service.Received(1).Get(expected.Id);
        }