예제 #1
0
        public async Task <ActionResult <WorkblockDto> > Create(CreatingWorkblockDto obj)
        {
            var dto       = WorkblockMapper.toDTO(obj);
            var workblock = await _service.AddAsync(dto);

            return(CreatedAtAction(nameof(GetGetById), new { Id = workblock.Id }, workblock));
        }
예제 #2
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingWorkblockDto request = new CreatingWorkblockDto("Workblock6", "VehicleDutyKey", new string[] { "Trip:1", "Trip:2" }, 34000, 45000);

            var mock = new Mock <IWorkblockService>();

            mock.Setup(service => service.AddAsync(It.IsAny <WorkblockDto>())).Returns(Task.FromResult(WorkblockMapper.toDTO(request)));
            WorkblocksController controller = new WorkblocksController(mock.Object);

            var result = await controller.Create(request);

            mock.Verify(service => service.AddAsync(It.IsAny <WorkblockDto>()), Times.AtLeastOnce());
            ActionResult <WorkblockDto> WorkblockDto = WorkblockMapper.toDTO(request);

            Assert.IsInstanceOfType(result, typeof(ActionResult <WorkblockDto>));
        }
예제 #3
0
        public async Task Post_NormalParameters_Sucess()
        {
            CreatingWorkblockDto creatingWorkblockDto = new CreatingWorkblockDto("Workblock6", "VehicleDutyKey", new string[] { "Workblock:1", "Workblock:2" }, 34000, 45000);

            WorkblockDto WorkblockDto   = WorkblockMapper.toDTO(creatingWorkblockDto);
            Workblock    Workblock      = WorkblockMapper.toDomain(WorkblockDto);
            var          mockRepository = new Mock <IWorkblockRepository>();

            mockRepository.Setup(repository => repository.AddAsync(It.IsAny <Workblock>())).Returns(Task.FromResult(Workblock));

            var mockUnit = new Mock <IUnitOfWork>();

            WorkblockService     WorkblockService = new WorkblockService(mockUnit.Object, mockRepository.Object);
            WorkblocksController controller       = new WorkblocksController(WorkblockService);

            var result = await controller.Create(creatingWorkblockDto);

            mockRepository.Verify(repository => repository.AddAsync(It.IsAny <Workblock>()), Times.AtLeastOnce());
            mockUnit.Verify(unit => unit.CommitAsync(), Times.AtLeastOnce());
            Assert.IsInstanceOfType(result, typeof(ActionResult <WorkblockDto>));
        }
예제 #4
0
        public void testToDto()
        {
            string        key            = "key1";
            string        vehicleDutyKey = "vdkey";
            int           startTime      = 1;
            int           endTime        = 1;
            List <String> lTripKey       = new List <string>()
            {
                "key1", "key2"
            };

            WorkblockDto mapperDto = WorkblockMapper.toDTO(new CreatingWorkblockDto(key, vehicleDutyKey, lTripKey.ToArray(), startTime, endTime));
            WorkblockDto wbdto     = new WorkblockDto(key, vehicleDutyKey, lTripKey, startTime, endTime);

            Assert.AreEqual(mapperDto.Key, wbdto.Key);
            Assert.AreEqual(mapperDto.VehicleDutyKey, wbdto.VehicleDutyKey);
            Assert.AreEqual(mapperDto.StartTime, wbdto.StartTime);
            Assert.AreEqual(mapperDto.EndTime, wbdto.EndTime);
            foreach (String s in wbdto.ListOfTrips)
            {
                Assert.IsNotNull(mapperDto.ListOfTrips.Contains(s));
            }
        }