public void ViewComponentInvocationTester_Test_methods_should_throw_exception_when_result_is_not_expected_IViewComponentResult_type() { ForTest.Scenarios ( new InvocationScenario( () => _viewComponentTester.Invocation(x => x.Invoke).TestResult <ContentViewComponentResult>(), typeof(ContentViewComponentResult), typeof(ViewViewComponentResult)), new InvocationScenario( () => _viewComponentTester.Invocation(x => x.Invoke).TestContent(), typeof(ContentViewComponentResult), typeof(ViewViewComponentResult)), new InvocationScenario( () => _viewComponentTester.Invocation(x => x.Invoke).TestHtmlContent(), typeof(HtmlContentViewComponentResult), typeof(ViewViewComponentResult)), new InvocationScenario( () => _viewComponentTester.Invocation(x => x.InvokeContent).TestView(), typeof(ViewViewComponentResult), typeof(ContentViewComponentResult)) ) .TestEach(scenario => { AssertExceptionThrown .OfType <ActionTestException>() .WithMessage($"Expected IViewComponentResult type {scenario.ExpectedTypeName}. Actual: {scenario.ActualTypeName}.") .WhenExecuting(() => scenario.TestAction()); }); }
public void divTest() { ForTest x = new ForTest(); double result = x.div(3, 2); Assert.AreEqual(1.5, result); }
public void ResolveRelativePath_should_return_expected_values() { ForTest.Scenarios ( new { Base = @"C:\SourceCode\sparky-test-helpers\.vs\SparkyTestHelpers\lut\0\t\SparkyTestHelpers.Xml.UnitTests\bin\Debug", Relative = "../../../../../../../../app.transform1.config", Expected = @"C:\SourceCode\sparky-test-helpers\app.transform1.config" }, new { Base = @"c:\folder\subfolder", Relative = @"something\web.config", Expected = @"c:\folder\subfolder\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"/something/web.config", Expected = @"c:\something\web.config" }, // Can use either forward or backward slashes: new { Base = @"c:\folder\subfolder", Relative = @"../../something/web.config", Expected = @"c:\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"..\..\something\web.config", Expected = @"c:\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"../something\web.config", Expected = @"c:\folder\something\web.config" }, new { Base = @"c:\folder\subfolder", Relative = @"..\something\web.config", Expected = @"c:\folder\something\web.config" }, // Full path ignores base: new { Base = @"c:\folder\subfolder", Relative = @"c:\different\subDifferent\web.config", Expected = @"c:\different\subDifferent\web.config" } ) .TestEach(scenario => Assert.AreEqual( scenario.Expected.ToLowerInvariant(), XmlTransformer.ResolveRelativePath(scenario.Base, scenario.Relative).ToLowerInvariant())); }
public void MsTest_ForTest_EnumValues_ExceptFor_should_ignore_unwanted_enum_values() { StringComparison[] stringComparisonValues = Enum.GetValues(typeof(StringComparison)).Cast <StringComparison>().ToArray(); StringComparison[] unwantedValues = new[] { StringComparison.CurrentCultureIgnoreCase, StringComparison.InvariantCultureIgnoreCase }; StringComparison[] wantedValues = stringComparisonValues.Except(unwantedValues).ToArray(); int callbackCount = 0; ForTest.EnumValues <StringComparison>() .ExceptFor(unwantedValues) .TestEach(scenario => { Assert.AreEqual(wantedValues[callbackCount], scenario); callbackCount++; }); Assert.AreEqual(wantedValues.Length, callbackCount); }
public ActionResult TestController() { ForTest foreTest = new ForTest(); foreTest.StringResultForTest = "some test"; return(View(foreTest)); }
public void addTest() { ForTest x = new ForTest(); int result = x.add(1, 1); Assert.AreEqual(2, result); }
private void TestProtobuf(out float timeSerialize, out float timeDeserialize) { // serialize var watch = System.Diagnostics.Stopwatch.StartNew(); var s = new ForTest(); s.Details.Add(Any.Pack(new Int32Value { Value = 10 })); s.Details.Add(Any.Pack(new StringValue { Value = "some text" })); var bytes = s.ToByteArray(); watch.Stop(); timeSerialize = watch.ElapsedTicks; // deserialize watch = System.Diagnostics.Stopwatch.StartNew(); var parsed = ForTest.Parser.ParseFrom(bytes); var intVal = parsed.Details[0].Unpack <Int32Value>(); var stringVal = parsed.Details[1].Unpack <StringValue>(); watch.Stop(); timeDeserialize = watch.ElapsedTicks; }
public void WithMessageMatching_should_handle_unmatched_message() { ForTest.Scenarios ( new { Message = "Something bad happened. ", Pattern = @"^Something bad happened\.$" }, new { Message = "Error 45.", Pattern = @"Error 4\d{2}" }, new { Message = "Invalid operation. SAD!", Pattern = @".*BAD\!" } ) .TestEach(scenario => { try { AssertExceptionThrown .OfType <InvalidOperationException>() .WithMessageMatching(scenario.Pattern) .WhenExecuting(() => throw new InvalidOperationException(scenario.Message)); } catch (ExpectedExceptionNotThrownException ex) { string expected = $"Expected message matching \"{scenario.Pattern}\". Actual: \"{scenario.Message}\"." + "\n(message from System.InvalidOperationException.)"; Assert.AreEqual(expected, ex.Message); } }); }
public void Scenario_Arrange_Assert_should_work_as_expected() { bool arrange1Called = false; bool arrange2Called = false; bool assert1Called = false; bool assert2Called = false; ForTest.Scenarios <TestClass1, TestClass2>() .Arrange(t1 => arrange1Called = true).Assert(t2 => assert1Called = true) .Arrange(t1 => arrange2Called = true).Assert(t2 => assert2Called = true) .TestEach(scenario => { var test1 = new TestClass1(); scenario.Arrange(test1); var test2 = new TestClass2(); scenario.Assert(test2); }); using (new AssertionScope()) { arrange1Called.Should().BeTrue(); assert1Called.Should().BeTrue(); arrange2Called.Should().BeTrue(); assert2Called.Should().BeTrue(); } }
public void ViewComponentTester_constructor_should_check_for_valid_ViewComponent_class() { ForTest.Scenarios ( new ConstructorScenario(true, () => new ViewComponentTester <ViewComponentInvocationTesterTests>(this)), new ConstructorScenario(true, () => new ViewComponentTester <ClassWithViewComponentAttribute>(new ClassWithViewComponentAttribute())), new ConstructorScenario(true, () => new ViewComponentTester <ClassWithNameEndingWithViewComponent>(new ClassWithNameEndingWithViewComponent())), new ConstructorScenario(false, () => new ViewComponentTester <InvalidViewComponentClass>(new InvalidViewComponentClass())) ) .TestEach(scenario => { if (scenario.IsValidViewComponent) { AssertExceptionNotThrown.WhenExecuting(scenario.ConstructorCall); } else { AssertExceptionThrown .OfType <ActionTestException>() .WithMessageStartingWith("A ViewComponent must inherit from ViewComponent, have a name ending with") .WhenExecuting(scenario.ConstructorCall); } }); }
public void bBigger() { var target = new ForTest(); var res = target.test("1", "2"); Assert.IsTrue(res == 3); }
public void aEqualsb() { var target = new ForTest(); var res = target.test("2", "2"); Assert.IsTrue(res == 4); }
public void aBigger() { var target = new ForTest(); var res = target.test("2", "1"); Assert.IsTrue(res == 1); }
public void abIsNull() { var target = new ForTest(); var res = target.test(null, null); Assert.IsNull(res); }
public void Setup() { messages = new List <MailMessage>(); ForTest.InitializeMailer(); var mailer = ForTest.TestMailer(m => messages.Add(m)); task = new SendInvoiceTask(mailer); }
public void abCanNotToInt() { var target = new ForTest(); var res = target.test("a", "b"); Assert.IsNull(res); }
public void Setup() { var promotionsToClean = session.Query <SupplierPromotion>().ToList(); session.DeleteEach(promotionsToClean); Flush(); messages = new List <MailMessage>(); ForTest.InitializeMailer(); }
public void Setup() { Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory; Global.Config.DocsPath = "../../../AdminInterface/Docs/"; Global.Config.RegisterListEmail = "*****@*****.**"; ForTest.InitialzeAR(); IntegrationFixture2.Factory = ActiveRecordMediator.GetSessionFactoryHolder().GetSessionFactory(typeof(ActiveRecordBase)); }
public void Any_Boolean_should_work() { ForTest.Scenarios(true, false) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithBoolean(scenario); _mock.Verify(x => x.WithBoolean(Any.Boolean), Times.Once); }); }
public void Any_DateTime_should_work() { ForTest.Scenarios(DateTime.Now, DateTime.Now.AddMonths(1)) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithDateTime(scenario); _mock.Verify(x => x.WithDateTime(Any.DateTime), Times.Once); }); }
public void Any_String_should_work() { ForTest.Scenarios("string1", "string2") .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithString(scenario); _mock.Verify(x => x.WithString(Any.String), Times.Once); }); }
public void Any_Double_should_work() { ForTest.Scenarios(1.0d, 2.0d) .TestEach(scenario => { _mock.ResetCalls(); _test.WithDouble(scenario); _mock.VerifyOneCallTo(x => x.WithDouble(Any.Double)); }); }
public void Any_Decimal_should_work() { ForTest.Scenarios(1.0m, 2.0m) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithDecimal(scenario); _mock.Verify(x => x.WithDecimal(Any.Decimal), Times.Once); }); }
public void Any_DateTime_should_work() { ForTest.Scenarios(DateTime.Now, DateTime.Now.AddMonths(1)) .TestEach(scenario => { _mock.ResetCalls(); _test.WithDateTime(scenario); _mock.VerifyOneCallTo(x => x.WithDateTime(Any.DateTime)); }); }
public void Any_Decimal_should_work() { ForTest.Scenarios(1.0m, 2.0m) .TestEach(scenario => { _mock.ResetCalls(); _test.WithDecimal(scenario); _mock.VerifyOneCallTo(x => x.WithDecimal(Any.Decimal)); }); }
public void Any_Boolean_should_work() { ForTest.Scenarios(true, false) .TestEach(scenario => { _mock.ResetCalls(); _test.WithBoolean(scenario); _mock.VerifyOneCallTo(x => x.WithBoolean(Any.Boolean)); }); }
public void Any_String_should_work() { ForTest.Scenarios("string1", "string2") .TestEach(scenario => { _mock.ResetCalls(); _test.WithString(scenario); _mock.VerifyOneCallTo(x => x.WithString(Any.String)); }); }
public void Any_Object_should_work() { ForTest.Scenarios(new { A = 1 }, new { A = 2 }) .TestEach(scenario => { _mock.ResetCalls(); _test.WithObject(scenario); _mock.VerifyOneCallTo(x => x.WithObject(Any.Object)); }); }
public void Any_Int_should_work() { ForTest.Scenarios(1, 2) .TestEach(scenario => { _mock.ResetCalls(); _test.WithInt(scenario); _mock.VerifyOneCallTo(x => x.WithInt(Any.Int)); }); }
public void Any_Double_should_work() { ForTest.Scenarios(1.0d, 2.0d) .TestEach(scenario => { _mock.Invocations.Clear(); _test.WithDouble(scenario); _mock.Verify(x => x.WithDouble(Any.Double), Times.Once); }); }