Beispiel #1
0
        public void UpdateNonexistantLoad()
        {
            //Automapper
            AutoMapperConfig.RegisterMappings();

            //Mock context
            Mock <FortuneDbContext> mockContext = new Mock <FortuneDbContext>();

            //Mock repos
            Mock <IRepo <Location> > mockLocationRepo = new Mock <IRepo <Location> >();
            Mock <IRepo <Trailer> >  mockTrailerRepo  = new Mock <IRepo <Trailer> >();
            Mock <IRepo <Load> >     mockLoadRepo     = new Mock <IRepo <Load> >();

            //Test location
            Location testLocation = new Location
            {
                Deleted = false,
                Id      = Guid.NewGuid(),
                Name    = "TEST LOCATION"
            };
            LocationDto testLocationDto = Mapper.Map <LocationDto>(testLocation);

            //Test Trailer
            Trailer testTrailer = new Trailer
            {
                Deleted    = false,
                Id         = 1,
                LocationId = testLocation.Id
            };
            TrailerDto testTrailerDto = Mapper.Map <TrailerDto>(testTrailer);

            testTrailerDto.Location = testLocationDto;

            //Test Load
            Load testLoad = new Load
            {
                Appointment   = DateTime.UtcNow,
                ArrivalTime   = DateTime.UtcNow,
                CfNum         = 1,
                Deleted       = false,
                DepartureTime = DateTime.UtcNow,
                DestinationId = testLocation.Id,
                Id            = Guid.NewGuid(),
                OriginId      = testLocation.Id,
                PuNum         = 1,
                Status        = LoadStatus.InTransit,
                TrailerId     = testTrailer.Id,
                Type          = LoadType.Inbound
            };
            LoadDto testLoadDto = Mapper.Map <LoadDto>(testLoad);

            testLoadDto.Trailer     = testTrailerDto;
            testLoadDto.Origin      = testLocationDto;
            testLoadDto.Destination = testLocationDto;

            //Mock Calls
            mockLoadRepo.Setup(x => x.Get(It.Is <Guid>(y => y == testLoad.Id))).Returns <Load>(null);
            mockTrailerRepo.Setup(x => x.Get(testTrailer.Id)).Returns(testTrailer);
            mockLocationRepo.Setup(x => x.Get(It.Is <Guid>(y => y == testLocation.Id))).Returns(testLocation);

            //Mock unit of work
            Mock <IUnitOfWork> mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.SetupGet(x => x.LocationRepo).Returns(mockLocationRepo.Object);
            mockUnitOfWork.SetupGet(x => x.TrailerRepo).Returns(mockTrailerRepo.Object);
            mockUnitOfWork.SetupGet(x => x.LoadRepo).Returns(mockLoadRepo.Object);

            //Load service
            LoadService loadService = new LoadService(mockUnitOfWork.Object);

            //Test
            LoadDto dto = loadService.Update(testLoadDto);
        }