コード例 #1
0
        public ThoughtModel Create(ThoughtModel thought)
        {
            var entity = thought.Map <ThoughtEntity>();
            var result = _thoughtRepository.Add(entity);

            return(result.Map <ThoughtModel>());
        }
コード例 #2
0
        public ThoughtModel Save(ThoughtModel thought)
        {
            var           entity = thought.Map <ThoughtEntity>();
            ThoughtEntity result = _thoughtRepository.Save(entity);

            return(result.Map <ThoughtModel>());
        }
コード例 #3
0
        private ThoughtModel GetRandomThought()
        {
            var model = new ThoughtModel()
            {
                Id = Guid.NewGuid()
            };

            return(model);
        }
コード例 #4
0
        public void ThoughtService_CreateThought_GetContainsIt()
        {
            // arrange
            IThoughtService service = GetServiceInstance();
            ThoughtModel    thought = GetRandomThought();

            // act
            service.Create(thought);

            // assert
            Assert.Equal(service.Get(thought.Id).Id, thought.Id);
        }
コード例 #5
0
        public void ThoughtService_SaveNewThought_GetAllContainsIt()
        {
            // arrange
            IThoughtService service = GetServiceInstance();
            ThoughtModel    thought = GetRandomThought();

            // act
            service.Save(thought);

            // assert
            Assert.Contains(service.GetAll(), t => t.Id == thought.Id);
        }
コード例 #6
0
        public void ThoughtValidator_GivenOldDate_ValidationFails(DateTime oldDateTime)
        {
            // arrange
            ThoughtModel              dummyThough = GetDummyThought(oldDateTime);
            Func <DateTime>           getDateTime = () => DateTime.Now;
            IValidator <ThoughtModel> validator   = new ThoughtValidator(getDateTime);

            // act
            bool validationResult = validator.IsValid(dummyThough);

            // assert
            Assert.False(validationResult);
        }
コード例 #7
0
        public void ThoughtService_DeleteThought_GetAllDoesntContainsIt()
        {
            // arrange
            IThoughtService service = GetServiceInstance();
            ThoughtModel    thought = GetRandomThought();

            // act
            service.Create(thought);
            Assert.Contains(service.GetAll(), t => t.Id == thought.Id);
            service.Delete(thought.Id);

            // assert
            Assert.DoesNotContain(service.GetAll(), t => t.Id == thought.Id);
        }
コード例 #8
0
        public void ThoughtService_UpdateThought_TitlesAreEquals()
        {
            // arrange
            string          dummyTitle = "I love bananas!";
            IThoughtService service    = GetServiceInstance();
            ThoughtModel    thought    = GetRandomThought();

            // act
            thought       = service.Create(thought);
            thought.Title = dummyTitle;
            thought       = service.Save(thought);

            // assert
            Assert.Equal(dummyTitle, thought.Title);
        }