예제 #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 void testSetParameters()
        {
            string        key            = "key1";
            string        vehicleDutyKey = "vdkey";
            int           startTime      = 1;
            int           endTime        = 1;
            List <String> lTripKey       = new List <string>()
            {
                "key1", "key2"
            };

            CreatingWorkblockDto cwbdto = new CreatingWorkblockDto(key, vehicleDutyKey, lTripKey.ToArray(), startTime, endTime);

            Assert.AreEqual(cwbdto.Key, key);
            Assert.AreEqual(cwbdto.VehicleDutyKey, vehicleDutyKey);
            Assert.AreEqual(cwbdto.StartTime, startTime);
            Assert.AreEqual(cwbdto.EndTime, endTime);
        }
예제 #4
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>));
        }