Esempio n. 1
0
            public async void WhenArgumentsAreValid_ThenResolverIsCalledOnceWithProperParameters()
            {
                // Arrange
                var intelligentBillboardResolverMock = new Mock <IIntelligentBillboardResolver>();

                intelligentBillboardResolverMock.Setup(r => r.ResolveAsync(It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
                .ReturnsAsync(_fixture.Create <IEnumerable <IntelligentBillboardRecommendation> >());

                var mapperMock = new Mock <IMapper>();

                mapperMock.Setup(r => r.DomainToApplicationModel(It.IsAny <Recommendation>()))
                .Returns(_fixture.Create <Models.Recommendation>());

                var from          = _fixture.Create <DateTime>();
                var weeks         = _fixture.Create <int>();
                var numBigRooms   = _fixture.Create <int>();
                var numSmallRooms = _fixture.Create <int>();
                var city          = _fixture.Create <string>();

                var sut = new BillboardService(intelligentBillboardResolverMock.Object, mapperMock.Object);

                // Act
                await sut.GetIntelligentBillboardAsync(from, weeks, numBigRooms, numSmallRooms, city);

                // Assert
                intelligentBillboardResolverMock.Verify(r => r.ResolveAsync(from, weeks, numBigRooms, numSmallRooms, city), Times.Once);
            }
Esempio n. 2
0
            public async void WhenResolverReturnsNull_ThenMapperIsNotCalled()
            {
                // Arrange
                var intelligentBillboardResolverMock = new Mock <IIntelligentBillboardResolver>();

                intelligentBillboardResolverMock.Setup(r => r.ResolveAsync(It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
                .ReturnsAsync((IEnumerable <IntelligentBillboardRecommendation>)null);

                var mapperMock = new Mock <IMapper>();

                mapperMock.Setup(r => r.DomainToApplicationModel(It.IsAny <Recommendation>()))
                .Returns(_fixture.Create <Models.Recommendation>());

                var from          = _fixture.Create <DateTime>();
                var weeks         = _fixture.Create <int>();
                var numBigRooms   = _fixture.Create <int>();
                var numSmallRooms = _fixture.Create <int>();
                var city          = _fixture.Create <string>();

                var sut = new BillboardService(intelligentBillboardResolverMock.Object, mapperMock.Object);

                // Act
                await sut.GetIntelligentBillboardAsync(from, weeks, numBigRooms, numSmallRooms, city);

                // Assert
                mapperMock.Verify(r => r.DomainToApplicationModel(It.IsAny <Recommendation>()), Times.Never);
            }
Esempio n. 3
0
            public void WhenNumberOfSmallRoomsArgumentIsNull_ThenArgumentNullExceptionIsThrown()
            {
                // Arrange
                var sut = new BillboardService(null, null);

                // Act
                Func <Task> func = async() => await sut.GetIntelligentBillboardAsync(_fixture.Create <DateTime>(), _fixture.Create <int>(), _fixture.Create <int>(), null, _fixture.Create <string>());

                // Assert
                func.Should().ThrowExactly <ArgumentNullException>();
            }
Esempio n. 4
0
            public void WhenCityArgumentIsNull_ThenOk()
            {
                // Arrange
                var intelligentBillboardResolverMock = new Mock <IIntelligentBillboardResolver>();

                intelligentBillboardResolverMock.Setup(r => r.ResolveAsync(It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
                .ReturnsAsync(_fixture.Create <IEnumerable <IntelligentBillboardRecommendation> >());

                var mapperMock = new Mock <IMapper>();

                mapperMock.Setup(r => r.DomainToApplicationModel(It.IsAny <Recommendation>()))
                .Returns(_fixture.Create <Models.Recommendation>());

                var sut = new BillboardService(intelligentBillboardResolverMock.Object, mapperMock.Object);

                // Act
                Func <Task> func = async() => await sut.GetIntelligentBillboardAsync(_fixture.Create <DateTime>(), _fixture.Create <int>(), _fixture.Create <int>(), _fixture.Create <int>(), null);

                // Assert
                func.Should().NotThrow <Exception>();
            }