public async Task CreateAsyncGenericShouldIncreaseCountUsingMoq()
        {
            AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly);

            var repository = new Mock <IDeletableEntityRepository <UserMessage> >();

            var messages = new List <UserMessage>
            {
                new UserMessage {
                    Id = "TestId1", CreatedOn = new DateTime(2020, 12, 31, 12, 12, 12), Subject = "TestSubject1", Email = "TestEmail1", Message = "TestMessage1", IP = "TestIp1"
                },
                new UserMessage {
                    Id = "TestId2", CreatedOn = new DateTime(2020, 12, 31, 12, 12, 13), Subject = "TestSubject2", Email = "TestEmail2", Message = "TestMessage2", IP = "TestIp2"
                },
            };

            repository.Setup(r => r.AddAsync(It.IsAny <UserMessage>())).Callback((UserMessage item) => messages.Add(item));
            repository.Setup(r => r.SaveChangesAsync()).Verifiable();

            var service = new UserMessagesService(repository.Object);
            var model   = new ContactFormInputViewModel
            {
                Subject = "TestSubject3",
                Email   = "TestEmail3",
                Message = "TestMessage3",
            };
            await service.CreateAsync(model, "TestIp3");

            Assert.Equal(3, messages.Count);

            repository.Verify(x => x.AddAsync(It.IsAny <UserMessage>()), Times.Once);
            repository.Verify(x => x.SaveChangesAsync());
        }
Example #2
0
        public IActionResult Index(ContactFormInputViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            this.mailService.SendContactFormEmailAsync(input.Email, input.Subject, input.Content, input.Name);
            return(this.View("ThankYou"));
        }
Example #3
0
        public IActionResult Contact()
        {
            if (this.User.Identity.IsAuthenticated)
            {
                ContactFormInputViewModel model = new ContactFormInputViewModel
                {
                    Email = this.User.Identity.Name,
                };

                return(this.View(model));
            }

            return(this.View());
        }
Example #4
0
        public async Task <IActionResult> Contact(ContactFormInputViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            this.TempData["Alert"] = "Thank you! Your request was sent successfully!";

            var ip = this.HttpContext.Connection.RemoteIpAddress.ToString();

            await this.userMessagesService.CreateAsync <ContactFormInputViewModel>(model, ip);

            return(this.RedirectToAction(nameof(this.Index)));
        }