ContactController.Index C# (CSharp) Method

Index() public method

public Index ( ) : void
return void
		public void Index()
		{
			// Here you could, for example, query the database for some
			// information about your company, and make it available
			// to the template using the "PropertyBag" property. 
			AddCountriesToPropertyBag();

			// The following line is required to allow automatic validation
			PropertyBag["contacttype"] = typeof(ContactInfo);
		}

Usage Example

Ejemplo n.º 1
0
        public void TestValidInputModel()
        {
            var model = new ContactInputModel()
            {
                Name    = "Pesho",
                Email   = "*****@*****.**",
                Subject = "Test subject",
                Message = "Hello from pesho's city",
            };

            var mockService = new Mock <IContactService>();

            mockService.Setup(x => x.SendEmail(model));

            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());
            var controller  = new ContactController(mockService.Object)
            {
                TempData = tempData,
            };

            var postResult = controller.Index(model);

            Assert.IsType <RedirectToPageResult>(postResult);
            Assert.True(controller.TempData.ContainsKey("Success"));
            Assert.Equal(
                "Your message has been sent. Be patient you will receive a reply within 1 day.",
                controller.TempData["Success"]);
        }
All Usage Examples Of ContactController::Index