public async Task CreateNewTestimonial(CreateTestimonialDto createTestimonialDto)
        {
            var testimonialCode = _databaseContext.TestimonialCodes.FirstOrDefault(tc => tc.Code == createTestimonialDto.TestimonialCode);

            if (testimonialCode == null)
            {
                throw new TestimonialCodeDoesNotExistException();
            }

            if (DateTime.Now > testimonialCode.ExpirationDateTime)
            {
                _databaseContext.TestimonialCodes.Remove(testimonialCode);
                await _databaseContext.SaveChangesAsync();

                throw new TestimonialCodeExpiredException();
            }

            var testimonial = new TestimonialModel(testimonialCode.FirstName, testimonialCode.LastName, testimonialCode.Description, createTestimonialDto.Testimonial);

            await _databaseContext.Testimonials.AddAsync(testimonial);

            _databaseContext.TestimonialCodes.Remove(testimonialCode);

            await _databaseContext.SaveChangesAsync();
        }
示例#2
0
        public async Task CreateNewTestimonial_AdditionalReviewSamePerson_Success()
        {
            // Definitions
            const string firstName          = "first;";
            const string lastName           = "last";
            const string description        = "description";
            const string code               = "123456";
            DateTime     expirationDateTime = DateTime.Now.AddDays(28);
            const string testimonial        = "testimonial";

            // Arrange
            _databaseContext.TestimonialCodes.Add(new TestimonialCodeModel(firstName, lastName, description, code, expirationDateTime));
            _databaseContext.Testimonials.Add(new TestimonialModel(firstName, lastName, description, testimonial));

            _databaseContext.SaveChanges();

            var createTestimonialDto = new CreateTestimonialDto(code, testimonial);
            var serviceUnderTest     = CreateServiceUnderTest();

            // Act
            await serviceUnderTest.CreateNewTestimonial(createTestimonialDto);

            // Assert
            _databaseContext.TestimonialCodes.Count().ShouldBe(0);
            _databaseContext.Testimonials.Count().ShouldBe(2);
            var databaseTestimonial = _databaseContext.Testimonials.FirstOrDefault();

            databaseTestimonial.ShouldNotBeNull();
            databaseTestimonial.FirstName.ShouldBe(firstName);
            databaseTestimonial.LastName.ShouldBe(lastName);
            databaseTestimonial.Description.ShouldBe(description);
            databaseTestimonial.Testimonial.ShouldBe(testimonial);
        }
示例#3
0
        public void CreateNewTestimonial_AdditionalReviewSamePerson_CodeDoesntExist()
        {
            // Definitions
            const string code        = "123456";
            const string testimonial = "testimonial";

            // Arrange
            var createTestimonialDto = new CreateTestimonialDto(code, testimonial);
            var serviceUnderTest     = CreateServiceUnderTest();

            // Act
            // Assert
            Should.Throw <TestimonialCodeDoesNotExistException>(async() => await serviceUnderTest.CreateNewTestimonial(createTestimonialDto));
        }
示例#4
0
        public async Task CreateNewTestimonial_AdditionalReviewSamePerson_CodeExpired()
        {
            // Definitions
            const string firstName          = "first;";
            const string lastName           = "last";
            const string description        = "description";
            DateTime     expirationDateTime = DateTime.Now.AddDays(-28);
            const string code        = "123456";
            const string testimonial = "testimonial";

            // Arrange
            var createTestimonialDto = new CreateTestimonialDto(code, testimonial);
            var serviceUnderTest     = CreateServiceUnderTest();

            await _databaseContext.TestimonialCodes.AddAsync(new TestimonialCodeModel(firstName, lastName, description, code, expirationDateTime));

            await _databaseContext.SaveChangesAsync();

            // Act
            // Assert
            Should.Throw <TestimonialCodeExpiredException>(async() => await serviceUnderTest.CreateNewTestimonial(createTestimonialDto));
        }
示例#5
0
        public async Task <IActionResult> CreateTestimonial([FromBody] CreateTestimonialDto createTestimonialDto)
        {
            await _testimonialsService.CreateNewTestimonial(createTestimonialDto);

            return(Ok());
        }