public void TitleFunctionCanBeOverridenWithinTestAndUseParameters() { GivenWeMutateSomeState(); FooClass something = new FooClass(); var context = TestContext.GetContext(something); Configurator.Scanners.SetDefaultStepTitleCreatorFunction((a, b, c, d, e) => new StepTitle(e + " " + c.Name + " " + string.Join(",", d.Select(arg => arg.Value).ToArray()))); new FluentStepBuilder <FooClass>(something); var story = something .Given(_ => GivenWeMutateSomeState()) .When(_ => something.Sub.SomethingHappens()) .And(_ => something.Sub.SomethingWithDifferentTitle()) .Then(_ => ThenTitleHas(AMethodCall())) .And(_ => something.Sub.SomethingWithArg("foo")) .And(_ => something.Sub.SomethingWithArg2("foo2")) .And(_ => something.Sub.SomethingWithArg3("foo3")) .BDDfy(); story.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("Given GivenWeMutateSomeState "); story.Scenarios.Single().Steps.ElementAt(1).Title.ShouldBe("When SomethingHappens "); story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("And SomethingWithDifferentTitle "); story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("Then ThenTitleHas Mutated state"); story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("And SomethingWithArg foo"); story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("And SomethingWithArg2 foo2"); story.Scenarios.Single().Steps.ElementAt(6).Title.ShouldBe("And SomethingWithArg3 foo3"); }
public void NullCheck_NullCustomClass_AsExpectedWhenNull() { FooClass value = null; var actual = NullCheck(value); Assert.Equal(ExpectedWhenNull, actual); }
public void NullCheck_DefaultConstructorCustomClass_AsExpectedWhenNotNull() { FooClass value = new FooClass(); var actual = NullCheck(value); Assert.Equal(ExpectedWhenNotNull, actual); }
public void Syntax_Normal_haha() { var foo = A.Fake <IFoo>(); var func = A.Fake <Func <string, int> >(); var foos = A.CollectionOfFake <Foo>(10); var type = GetTypeOfFake(); object fake = Create.Fake(type); IList <object> fakes = Create.CollectionOfFake(type, 10); // Specifying arguments for constructor using expression. This is refactoring friendly! // The constructor seen here is never actually invoked. It is an expression and it's purpose // is purely to communicate the constructor arguments which will be extracted from it var foo1 = A.Fake <FooClass>(x => x.WithArgumentsForConstructor(() => new FooClass("foo", "bar"))); // Specifying arguments for constructor using IEnumerable<object>. var foo2 = A.Fake <FooClass>(x => x.WithArgumentsForConstructor(new object[] { "foo", "bar" })); // Specifying additional interfaces to be implemented. Among other uses, // this can help when a fake skips members because they have been // explicitly implemented on the class being faked. var foo3 = A.Fake <FooClass>(x => x.Implements(typeof(IFoo))); // or var foo4 = A.Fake <FooClass>(x => x.Implements <IFoo>()); // Assigning custom attributes to the faked type. // foo's type should have "FooAttribute" var foo5 = A.Fake <IFoo>(x => x.WithAttributes(() => new FooAttribute())); // Create wrapper - unconfigured calls will be forwarded to wrapped var wrapped = new FooClass("foo", "bar"); var foo6 = A.Fake <IFoo>(x => x.Wrapping(wrapped)); }
public void FailingTest() { var sut = new FooClass(); var result = sut.GetHello(); result.ShouldBe("bad value"); }
public void BarMethod(Type t) { FooClass.FooMethod() //works fine if (t == typeof(FooClass)) { t.GetMethod("FooMethod").Invoke(null, null); //null - means calling static method } }
public void BarMethod(Type t) { FooClass.FooMethod(); //works fine if (t == typeof(FooClass)) { t.GetMethod("FooMethod").Invoke(null, null); // (null, null) means calling static method with no parameters } }
static void Main(string[] args) { FooStruct f = new FooStruct(); f.Val = 2; FooClass f2 = (FooClass)f; Console.Read(); }
protected override void ExecuteInternal() { var fooClassInstance = new FooClass(); Console.WriteLine("Foo class instance created. Press ENTER to continue..."); Console.ReadLine(); GC.KeepAlive(fooClassInstance); }
public void EqualsMustReturnFalseIfCheckedObjectIsNotCoordinate() { // Given Coordinate coord = new Coordinate(10, 20); FooClass foo = new FooClass(); // When / Then Assert.IsFalse(coord.Equals(foo), "Equals must return false if checked object is from a different class"); }
public MainWindow() { InitializeComponent(); var foo = new FooClass(); foo.Raw = new ObservableCollection <string>(new List <string> { "1", "2", "3" }); DataContext = foo; }
// Liveness for param area public static int test_0_liveness_12() { var f = new FooClass() { s = "A" }; // The ref argument should be passed on the stack liveness_12_inner(1, 2, 3, 4, 5, 6, new object(), ref f.s); return(0); }
public void InvokeGenericMethodByNullObjShouldThrowArgumentNullException() { // Arrange var reflectionHelper = GetReflectionHelper(); var parameter = new FooClass { Data = "test" }; // Assert Assert.Throws(typeof(ArgumentNullException), () => reflectionHelper.InvokeGenericMethod("BarMethod", null, parameter, typeof(IBarInterface <>))); }
public void InvokeGenericMethodByNullGenericInterfaceTypeShouldThrowArgumentNullException() { // Arrange var reflectionHelper = new ReflectionHelper(); var barClass = new BarClass(); var parameter = new FooClass { Data = "test" }; // Assert Assert.Throws(typeof(ArgumentNullException), () => reflectionHelper.InvokeGenericMethod("BarMethod", barClass, parameter, null)); }
public void TestCompareClasses1() { FooClass c1 = new FooClass(); FooClass c2 = new FooClass(); c1.i1 = c2.i1 = 2; c1.i2 = c2.i2 = 265465; c1.ii1 = c2.ii1 = 47563846758376528L; c1.ii2 = c2.ii2 = 4562523256235645653L; c1.s1 = c2.s1 = "foo bar test"; c1.s2 = c2.s2 = "fdkjhgkdfsghskdjfhgkusziwu.lerg"; Assert.AreEqual(true, CommonUtilities.CompareClasses(c1, c2)); }
public void InvokeGenericMethodByInvalidInterfaceTypeShouldThrowInvalidOperationException() { // Arrange var reflectionHelper = GetReflectionHelper(); var barClass = new BarClass(); var parameter = new FooClass { Data = "test" }; // Assert Assert.Throws(typeof(InvalidOperationException), () => reflectionHelper.InvokeGenericMethod("BarMethod", barClass, parameter, typeof(IBarInterface <string>))); }
public void TestCompareClasses2() { FooClass c1 = new FooClass(); FooClass c2 = new FooClass(); c1.i1 = c2.i1 = 2; c1.i2 = c2.i2 = 265465; c1.ii1 = c2.ii1 = 47563846758376528L; c1.ii2 = c2.ii2 = 4562523256235645653L; c1.s1 = c2.s1 = null; c1.s2 = c2.s2 = null; Assert.AreEqual(true, CommonUtilities.CompareClasses(c1, c2)); }
private static void Example(object someObj) { var type = someObj.GetType(); if (typeof(IInterfaceA).IsAssignableFrom(type) && typeof(IInterfaceB).IsAssignableFrom(type)) { var genericMethod = typeof(FooClass).GetMethod("Foo"); var constructedMethod = genericMethod.MakeGenericMethod(type); var instance = new FooClass(); var result = constructedMethod.Invoke(instance, new [] { someObj }); Assert.IsNull(result); } }
public void InvokeGenericMethodByNullOrWhitespaceNameShouldThrowArgumentNullException() { // Arrange var reflectionHelper = GetReflectionHelper(); var barClass = new BarClass(); var parameter = new FooClass { Data = "test" }; // Assert Assert.Throws(typeof(ArgumentNullException), () => reflectionHelper.InvokeGenericMethod(string.Empty, barClass, parameter, typeof(IBarInterface <>))); }
public void InvokeGenericMethodShouldCallGivenMethod() { // Arrange var reflectionHelper = GetReflectionHelper(); var barClass = new BarClass(); var parameter = new FooClass { Data = "test" }; // Act reflectionHelper.InvokeGenericMethod("BarMethod", barClass, parameter, typeof(IBarInterface <>)); // Assert Assert.True(barClass.Data == "test"); }
static void Main(string[] args) { var ret = FooClass.InstanceCreationEditor(); if (ret == typeof(FooClass).Name) { Console.WriteLine(true); } var ret1 = BooClass.InstanceCreationEditor(); if (ret1 == typeof(BooClass).Name) { Console.WriteLine(true); } }
public void RestoreTest() { FooClass foo = new FooClass(); //AspectW.Define // .Restore( //AspectW aspect = null; // TODO: 初始化為適當值 //object v = null; // TODO: 初始化為適當值 //Action<object> setter = null; // TODO: 初始化為適當值 //AspectW expected = null; // TODO: 初始化為適當值 //AspectW actual; //actual = AspectWExtensions.Restore(aspect, v, setter); //Assert.AreEqual(expected, actual); //Assert.Inconclusive("驗證這個測試方法的正確性。"); }
public void WhenITryToReadAFile() { // Arrange var mapper = A.Fake <IMapper>(); var filePath = string.Empty; //var reader //var reader = A.Fake<IReader>( // x => x.WithArgumentsForConstructor( // () => new Reader(mapper))); // Act A.CallTo(() => reader.ReadAsync(filePath)).Returns(lollipop); // Assert // Specifying arguments for constructor using IEnumerable<object>. var foo = A.Fake <FooClass>(x => x.WithArgumentsForConstructor(new object[] { "foo", "bar" })); // Specifying additional interfaces to be implemented. Among other uses, // this can help when a fake skips members because they have been // explicitly implemented on the class being faked. var foo = A.Fake <FooClass>(x => x.Implements(typeof(IFoo))); // or var foo = A.Fake <FooClass>(x => x.Implements <IFoo>()); // Assigning custom attributes to the faked type. // foo's type should have "FooAttribute" var foo = A.Fake <IFoo>(x => x.WithAttributes(() => new FooAttribute())); // Create wrapper - unconfigured calls will be forwarded to wrapped var wrapped = new FooClass("foo", "bar"); var foo = A.Fake <IFoo>(x => x.Wrapping(wrapped)); //// Arrange //var mapper = A.Fake<IMapper>(); //var model = A.Fake<BaseModel>(); //// Act //var result = new Reader(mapper); //// Assert //result.ReadAsync<BaseModel>(string.Empty); }
static void Main(string[] args) { FooClass fooClass = new FooClass(); fooClass.FooMethod(); ((IFoo)fooClass).FooMethod(); ((IBar)fooClass).FooMethod(); BarClass barClass = new BarClass(); barClass.FooMethod(); ((IFoo)barClass).FooMethod(); ((IBar)barClass).FooMethod(); FooBar foobar = new FooBar(); foobar.FooMethod(); ((IFoo)foobar).FooMethod(); ((IBar)foobar).FooMethod(); System.Console.ReadKey(); }
public static void Negative() { FooClass fooObj = new FooClass(); IFoo foo = (IFoo)fooObj; Console.WriteLine("Calling IFoo.Foo on Foo - expecting exception."); try { foo.Foo(10); Test.Assert(false, "Expecting exception on Foo"); } catch (Exception ex) { Console.WriteLine("Exception caught: " + ex.ToString()); } I47Class i47Class = new I47Class(); I1 i1 = (I1)i47Class; Console.WriteLine("Calling I1.Func on I47Class - expecting exception"); try { i1.Func(10); Test.Assert(false, "Expecting exception on I47Class"); } catch (Exception ex) { Console.WriteLine("Exception caught: " + ex.ToString()); } var gi23Class = new GI23Class <object>(); GI1 <object> gi1 = (GI1 <object>)gi23Class; Console.WriteLine("Calling GI1<T>.Func on GI23Class<S> - expecting exception"); try { Type[] types; gi1.Func <string>(out types); Test.Assert(false, "Expecting exception on GI23Class"); } catch (Exception ex) { Console.WriteLine("Exception caught: " + ex.ToString()); } }
public void MethodCallInStepTitle() { FooClass something = new FooClass(); var story = this .Given(_ => GivenWeMutateSomeState()) .When(_ => something.Sub.SomethingHappens()) .And(_ => something.Sub.SomethingWithDifferentTitle()) .Then(_ => ThenTitleHas(AMethodCall())) .And(_ => something.Sub.SomethingWithArg("foo")) .And(_ => something.Sub.SomethingWithArg2("foo")) .And(_ => something.Sub.SomethingWithArg3("foo")) .BDDfy(); story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("And different title"); story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("Then title has Mutated state"); story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("And with arg foo"); story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("And with arg"); story.Scenarios.Single().Steps.ElementAt(6).Title.ShouldBe("And with foo arg"); }
public void TitleFunctionCanBeOverriden() { FooClass something = new FooClass(); var context = TestContext.GetContext(something); Configurator.Scanners.SetDefaultStepTitleCreatorFunction((a, b, c, d, e) => new StepTitle("hello")); new FluentStepBuilder <FooClass>(something); var story = something .Given(_ => GivenWeMutateSomeState()) .When(_ => something.Sub.SomethingHappens()) .And(_ => something.Sub.SomethingWithDifferentTitle()) .Then(_ => ThenTitleHas(AMethodCall())) .And(_ => something.Sub.SomethingWithArg("foo")) .And(_ => something.Sub.SomethingWithArg2("foo")) .And(_ => something.Sub.SomethingWithArg3("foo")) .BDDfy(); story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("hello"); story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("hello"); story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("hello"); story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("hello"); story.Scenarios.Single().Steps.ElementAt(6).Title.ShouldBe("hello"); }
public void TitleFunctionCanBeOverridenFromThestartWithinTestAndUseParameters() { GivenWeMutateSomeState(); FooClass something = new FooClass(); var context = TestContext.GetContext(something); new FluentStepBuilder <FooClass>(something); var story = something .SetStepTitleFunction((a, b, c, d, e) => new StepTitle("hello")) .Given(_ => GivenWeMutateSomeState()) .When(_ => something.Sub.SomethingHappens()) .BDDfy(); story.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("hello"); story.Scenarios.Single().Steps.ElementAt(1).Title.ShouldBe("hello"); var story2 = something .Given(_ => GivenWeMutateSomeState()) .BDDfy(); story2.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("Given we mutate some state"); }
public static int test_0_intrins_object_ctor () { object o = new FooClass (); return (o != null) ? 0 : 1; }
public Load_Constructor_Complex_Argument(FooClass foo) { this.Foo = foo; }
public void TestPrivateMethod() { var fooObject = new FooClass(); Assert.AreEqual("Hello from internal method", fooObject.InternalMethod()); }
public Map_Constructor_Complex_Argument_To_Null_When_All_Arguments_And_Subproperties_Are_Null(FooClass foo) { this.Foo = foo; }
public static int test_0_intrins_object_ctor() { object o = new FooClass(); return((o != null) ? 0 : 1); }
public Load_Complex_Property() { this.Foo = new FooClass { A = 1 }; }
// Liveness for param area public static int test_0_liveness_12 () { var f = new FooClass () { s = "A" }; // The ref argument should be passed on the stack liveness_12_inner (1, 2, 3, 4, 5, 6, new object (), ref f.s); return 0; }
public void ClassToClass_CanCast() { var foo = new FooClass { fieldA = "FooClass.fieldA", fieldB = "FooClass.fieldB" }; var bar = VeryUnsafeCast<FooClass, BarClass>.Cast(foo); Assert.Equal(bar.fieldC, foo.fieldA); Assert.Equal(bar.fieldD, foo.fieldB); }
public void ClassToStruct_CannotCast_Should_Throw_InvalidCastException() { // Structs and classes have different layout in memory. // So a naive cast will likely blow up. We don't allow this and throw. var foo = new FooClass { fieldA = "FooClass.FieldA", fieldB = "FooClass.FieldB" }; Assert.Throws<InvalidCastException>(() => VeryUnsafeCast<FooClass, BarStruct>.Cast(foo)); }
private static BarClass GetBarClassFromFoo() { var foo = new FooClass { fieldA = "fieldA", fieldB = "fieldB" }; return VeryUnsafeCast<FooClass, BarClass>.Cast(foo); }