public void LoadConfiguration() { Mock<IApiMeterConfiguration> configMock = new Moq.Mock<IApiMeterConfiguration>(); configMock.SetupProperty(d => d.RedisServerUrl, "localhost"); configMock.SetupProperty(d => d.RedisServerPort, 6379); configMock.SetupProperty(d => d.RedisConnectionTimeout, 1000); configMock.SetupProperty(d => d.RedisSendTimeout, 500); configMock.SetupProperty(d => d.RedisTimeToLive, 30); configuration = configMock.Object; data = RequestResponseDataGenerator.GetSample(); }
public void SendMailTestFixture() { //Create a mock object of a MailClient class which implements IMailClient var mockMailClient = new Moq.Mock <IMailClient>(); //Mock the properties of MailClient //(Setup the properties of dummy class to use defautl values) mockMailClient.SetupProperty(client => client.Server, "chat.mail.com").SetupProperty(client => client.Port, "1212"); //Configure dummy method so that it return true when it gets any string as parameters to the method mockMailClient.Setup(client => client.SendMail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); IMailer mailer = new DefaultMailer() { From = "*****@*****.**", To = "*****@*****.**", Subject = "Using Moq", Body = "Moq is awesome" }; //Use the mock object of MailClient instead of actual object var result = mailer.SendMail(mockMailClient.Object); //Verify that it return true Assert.IsTrue(result); //Verify that the MailClient's SendMail methods gets called exactly once when string is passed as parameters mockMailClient.Verify(client => client.SendMail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public void HomeErrorReturnsHttpContextTraceId() { var controller = new HomeController(); controller.ControllerContext = new ControllerContext(); var mockContext = new Moq.Mock <HttpContext>(); mockContext.SetupProperty <string>(p => p.TraceIdentifier, "124"); controller.ControllerContext.HttpContext = mockContext.Object; var result = controller.Error() as ViewResult; Assert.AreEqual("124", result.ViewData["requestId"]); }
public void IsLoadPageFillingProperties() { // Arrange Moq.Mock<IDashboardView> mockView = new Moq.Mock<IDashboardView>(); mockView.SetupProperty(c => c.BeginDateJobSummaryValue, new DateTime()); mockView.SetupProperty(c => c.EndDateJobSummaryValue, new DateTime()); mockView.SetupProperty(c => c.BeginDateCallLogViewFilter, new DateTime()); mockView.SetupProperty(c => c.EndDateCallLogViewFilter, new DateTime()); mockView.SetupProperty(c => c.DashBoardViewType, Globals.Dashboard.ViewType.JobCallLogView); DashboardViewModel viewModel = new DashboardViewModel(mockView.Object, new FakeUnitOfWork()); DateTime beginDate = DateTime.Now.AddDays(-4); DateTime endDate = DateTime.Now; // Act viewModel.LoadPage(); // Assert Assert.AreEqual(beginDate.ToString("MM/dd/yyyy"), mockView.Object.BeginDateJobSummaryValue.ToString("MM/dd/yyyy")); Assert.AreEqual(beginDate.ToString("MM/dd/yyyy"), mockView.Object.BeginDateCallLogViewFilter.ToString("MM/dd/yyyy")); Assert.AreEqual(endDate.ToString("MM/dd/yyyy"), mockView.Object.EndDateJobSummaryValue.ToString("MM/dd/yyyy")); Assert.AreEqual(endDate.ToString("MM/dd/yyyy"), mockView.Object.EndDateCallLogViewFilter.ToString("MM/dd/yyyy")); Assert.AreEqual(Globals.Dashboard.ViewType.JobCallLogView, mockView.Object.DashBoardViewType); }
public void SendMailTestFixture() { //Arrage var mockMailClient = new Moq.Mock <IMailClient>(); mockMailClient.SetupProperty(client => client.Server, "chat.mail.com").SetupProperty(client => client.Port, "1212"); mockMailClient.Setup(client => client.SendMail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); IMailer mailer = new DefaultMailer() { From = "*****@*****.**", To = "*****@*****.**", Subject = "Using Moq", Body = "Moq is awesome" }; //Act var result = mailer.SendMail(mockMailClient.Object); //Assert Assert.IsTrue(result); mockMailClient.Verify(client => client.SendMail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }
public void TestMethodMailToSend() { var moqMail = new Moq.Mock <IMailClient>(); moqMail.SetupProperty(client => client.Server, "chat.mail.com") .SetupProperty(client => client.Port, "80"); moqMail.Setup(client => client.SendMail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); IMailer mailer = new DefaultMailer() { From = "*****@*****.**", To = "*****@*****.**", Subject = "Using Moq", Body = "Moq is awesome" }; //Use the mock object of MailClient instead of actual object var result = mailer.SendMail(moqMail.Object); //Verify that it return true Assert.IsTrue(result); // Verify that the MailClient's SendMail methods gets called exactly once when string is passed as parameters moqMail.Verify(client => client.SendMail(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); }