コード例 #1
0
        public void GetAllDestinations_ShouldReturn_All_DestViewModels()
        {
            var destRepoBuilder = new DestinationsRepositoryBuilder();
            var destRepo        = destRepoBuilder
                                  .WithAll()
                                  .Build();

            var sut = new DestinationService(destRepo, null, null, null, null, null, null, this.Mapper);

            var actual   = sut.GetAllDestinations();
            var expected = new List <DestViewModel>
            {
                new DestViewModel {
                    Id = "1"
                }, new DestViewModel {
                    Id = "2"
                },
                new DestViewModel {
                    Id = "3"
                }, new DestViewModel {
                    Id = "4"
                }
            }.AsQueryable();

            Assert.Equal(expected, actual, new DestViewModelComparer());

            destRepoBuilder.DestRepoMock.Verify();
            destRepoBuilder.DestRepoMock.Verify(d => d.AddAsync(It.IsAny <Destination>()), Times.Never);
            destRepoBuilder.DestRepoMock.Verify(d => d.SaveChangesAsync(), Times.Never);
        }
        public DestinationPresenter(IDestinationView view, ProductModel selectedProduct)
        {
            _view = view;

            SelectedProduct = selectedProduct;

            _destinationMapper = new DestinationMapper();

            _transportMapper = new TransportMapper();

            _productMapper = new ProductMapper();

            _orderMapper = new OrderMapper();

            _orderStatusMapper = new OrderStatusMapper();

            _unitOfWork = new UnitOfWork(new ApplicationContext());

            destinationService = new DestinationService(_unitOfWork);

            transportService = new TransportService(_unitOfWork);

            orderService = new OrderService(_unitOfWork);

            OrderStatusService = new OrderStatusService(_unitOfWork);

            destinations = destinationService.GetAllDestinations().Select(dest => _destinationMapper.FromDomainToModel(dest)).ToList();

            _view.DisplayData(destinations);

            _view.DestinationSelected += BeginOrderCreation;
        }
コード例 #3
0
        public void BeCalled_WhenParamsAreValid()
        {
            //Arrange
            var mockedRepository   = new Mock <IEFRepository <Destination> >();
            var mockedUnitOfWork   = new Mock <IUnitOfWork>();
            var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object);

            //Act
            destinationService.GetAllDestinations();

            //Assert
            mockedRepository.Verify(repository => repository.All(), Times.Once);
        }
コード例 #4
0
        public void ThrowException_WhenNullDestination()
        {
            //Arrange
            var mockedRepository   = new Mock <IEFRepository <Destination> >();
            var mockedUnitOfWork   = new Mock <IUnitOfWork>();
            var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object);

            //Act
            IEnumerable <Destination> result = null;

            mockedRepository.Setup(repository => repository.All()).Returns(() => result.AsQueryable());

            //Assert
            Assert.Throws <ArgumentNullException>(() => destinationService.GetAllDestinations());
        }
コード例 #5
0
        public void ReturnEmptyCollection_WhenNoDestinations()
        {
            //Arrange
            var mockedRepository   = new Mock <IEFRepository <Destination> >();
            var mockedUnitOfWork   = new Mock <IUnitOfWork>();
            var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object);

            //Act
            IEnumerable <Destination> result = new List <Destination>();

            mockedRepository.Setup(repository => repository.All()).Returns(() => result.AsQueryable());

            //Assert
            Assert.IsEmpty(destinationService.GetAllDestinations());
        }
コード例 #6
0
        public void WorksProperly_WhenInvoked()
        {
            //Arrange
            var mockedRepository   = new Mock <IEFRepository <Destination> >();
            var mockedUnitOfWork   = new Mock <IUnitOfWork>();
            var destinationService = new DestinationService(mockedRepository.Object, mockedUnitOfWork.Object);

            //Act
            IEnumerable <Destination> result = new List <Destination>()
            {
                new Destination(), new Destination(), new Destination()
            };

            mockedRepository.Setup(repository => repository.All()).Returns(() => result.AsQueryable());

            //Assert
            Assert.AreEqual(destinationService.GetAllDestinations(), result);
        }
コード例 #7
0
        public void GetAllDestinations_ShouldReturn_EmptyCollection_IfIsEmpty()
        {
            var destinations = new List <Destination>().AsQueryable();

            var destRepoMock = new Mock <IRepository <Destination> >();

            destRepoMock.Setup(d => d.All())
            .Returns(destinations).Verifiable();

            var sut = new DestinationService(destRepoMock.Object, null, null, null, null, null, null, this.Mapper);

            var actual   = sut.GetAllDestinations();
            var expected = new List <DestViewModel>().AsQueryable();

            Assert.Equal(expected, actual, new DestViewModelComparer());

            destRepoMock.Verify();
            destRepoMock.Verify(d => d.AddAsync(It.IsAny <Destination>()), Times.Never);
            destRepoMock.Verify(d => d.SaveChangesAsync(), Times.Never);
        }