Beispiel #1
0
        public void Update()
        {
            // Arrange
            var updateSet = new Set
            {
                Id        = 2,
                SpentTime = new TimeWO {
                    Hours = 0, Minutes = 5, Seconds = 55
                }
            };

            _mock.Setup(s => s.Update(It.IsAny <SetDTO>())).Returns <SetDTO>(updateValue =>
            {
                updateValue.ModifiedDate = DateTime.Now;
                var setIndex             = _sets.FindIndex(set => set.Id == updateValue.Id);
                _sets[setIndex]          = updateValue;

                return(new OperationResult
                {
                    ResultItemId = updateValue.Id,
                    Succeed = true
                });
            });

            // Act
            var result          = _setController.Update(updateSet);
            var operationResult = result as OkNegotiatedContentResult <IOperationResult>;

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <IOperationResult>));
            Assert.IsTrue(operationResult.Content.Succeed);
            Assert.IsTrue(operationResult.Content.ResultItemId > 0);
            Assert.AreEqual(_sets.Find(set => set.Id == updateSet.Id).SpentTime, TimeWoOperations.FromTimeWoToSeconds(updateSet.SpentTime));
        }
Beispiel #2
0
        public static void RegisterMappings()
        {
            _mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <TrainingType, TrainingTypeDTO>();
                cfg.CreateMap <TrainingTypeDTO, TrainingType>();

                cfg.CreateMap <Training, TrainingDTO>();
                cfg.CreateMap <TrainingDTO, Training>();

                cfg.CreateMap <Exercise, ExerciseDTO>();
                cfg.CreateMap <ExerciseDTO, Exercise>();

                cfg.CreateMap <Set, SetDTO>()
                .ForMember(dest => dest.PlannedTime,
                           opt => opt.MapFrom(src => TimeWoOperations.FromTimeWoToSeconds(src.PlannedTime)))
                .ForMember(dest => dest.SpentTime,
                           opt => opt.MapFrom(src => TimeWoOperations.FromTimeWoToSeconds(src.SpentTime)))
                .ForMember(dest => dest.TimeForRest,
                           opt => opt.MapFrom(src => TimeWoOperations.FromTimeWoToSeconds(src.TimeForRest)));

                cfg.CreateMap <SetDTO, Set>()
                .ForMember(dest => dest.PlannedTime,
                           opt => opt.MapFrom(src => TimeWoOperations.FromSecondsToTimeWo(src.PlannedTime)))
                .ForMember(dest => dest.SpentTime,
                           opt => opt.MapFrom(src => TimeWoOperations.FromSecondsToTimeWo(src.SpentTime)))
                .ForMember(dest => dest.TimeForRest,
                           opt => opt.MapFrom(src => TimeWoOperations.FromSecondsToTimeWo(src.TimeForRest)));

                cfg.CreateMap <Approach, ApproachDTO>()
                .ForMember(dest => dest.PlannedTimeForRest,
                           opt => opt.MapFrom(src => TimeWoOperations.FromTimeWoToSeconds(src.PlannedTimeForRest)))
                .ForMember(dest => dest.SpentTimeForRest,
                           opt => opt.MapFrom(src => TimeWoOperations.FromTimeWoToSeconds(src.SpentTimeForRest)));

                cfg.CreateMap <ApproachDTO, Approach>()
                .ForMember(dest => dest.PlannedTimeForRest,
                           opt => opt.MapFrom(src => TimeWoOperations.FromSecondsToTimeWo(src.PlannedTimeForRest)))
                .ForMember(dest => dest.SpentTimeForRest,
                           opt => opt.MapFrom(src => TimeWoOperations.FromSecondsToTimeWo(src.SpentTimeForRest)));

                cfg.CreateMap <LogEntry, LogEntryDTO>();
                cfg.CreateMap <LogEntryDTO, LogEntry>();
            });
        }
        public void Update()
        {
            //Arrange
            var plannedTimeForRest = new TimeWO {
                Hours = 0, Minutes = 10, Seconds = 30
            };
            var spentTimeForRest = new TimeWO {
                Hours = 0, Minutes = 5, Seconds = 10
            };

            var updateApproach = new Approach
            {
                Id = 2,
                PlannedTimeForRest = plannedTimeForRest,
                SpentTimeForRest   = spentTimeForRest
            };

            _mock.Setup(s => s.Update(It.IsAny <ApproachDTO>())).Returns <ApproachDTO>(approach =>
            {
                approach.ModifiedDate        = DateTime.Now;
                var indexUpdateItem          = _approaches.FindIndex(ap => ap.Id == approach.Id);
                _approaches[indexUpdateItem] = approach;

                return(new OperationResult
                {
                    ResultItemId = approach.Id,
                    Succeed = true
                });
            });

            //Act
            var result          = _approachController.Update(updateApproach);
            var operationResult = result as OkNegotiatedContentResult <IOperationResult>;

            //Assert
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <IOperationResult>));
            Assert.IsTrue(operationResult.Content.Succeed);
            Assert.AreEqual(TimeWoOperations.FromTimeWoToSeconds(plannedTimeForRest), _approaches.Find(ap => ap.Id == updateApproach.Id).PlannedTimeForRest);
            Assert.AreEqual(TimeWoOperations.FromTimeWoToSeconds(spentTimeForRest), _approaches.Find(ap => ap.Id == updateApproach.Id).SpentTimeForRest);
        }