Beispiel #1
0
        public void ForAClass()
        {
            var result =
                new AnythingActivator(new CreateFromMock(typeof(INterface)))
                .New <ClassWith1ConstructorParam <INterface> >();

            //
            Assert.That(result.Param1, x => CreateFromMock.IsAKnownMock(x));
        }
Beispiel #2
0
 public void ButIfFactoryMethodIsMissing_ThenCreateFromFactoryMethodAttributeConstructorThrows()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         new CreateFromFactoryMethod(typeof(AClass),
                                     typeof(AFactory),
                                     "BuildMethodNameWhichDoesntExist");
     });
 }
Beispiel #3
0
        public void ThereIsAMockingFrameworkInTheBaseDirectory()
        {
            var moq = new FindInAssembly("Moq").FindTypeAssignableTo("Mock`1");

            //
            Assert.That(moq,
                        Is.NotNull,
                        "Didn't find a known mock framework (i.e. Moq) in Base Directory, can't test mocking.");
        }
        public void ForAClass()
        {
            var myObject = new AClass();
            var result   =
                new AnythingActivator(DefaultRules.All.After(new ActivateInstances(myObject)))
                .New <AClass>();

            //
            Assert.That(myObject == result);
        }
Beispiel #5
0
        public void ForAClass()
        {
            var myObject = new AClass();
            var result   =
                new AnythingActivator(
                    DefaultRules.All
                    .Union(new ActivateForType <AClass>(myObject)))
                .New <AClass>();

            //
            Assert.That(myObject == result);
        }
Beispiel #6
0
        public void ButIfFactoryMethodIsMissing_ThenAAThrows_WithOrWithoutAnAnchor()
        {
            var rules = new[] { new CreateFromFactoryMethod(typeof(AClass), "BuildMethodNameWhichDoesntExist") };

            //
            Assert.Throws <InvalidOperationException>(
                () => new AnythingActivator(rules, andUseDefaultRules: false).New <AClass>()
                );
            Assert.Throws <InvalidOperationException>(
                () => new AnythingActivator(
                    this,
                    instances: null,
                    rules: rules,
                    andUseDefaultRules: false)
                .New <AClass>()
                );
        }
        public void ForAFuncOf()
        {
            var myObject = new AClass();
            var myString = "String!";

            //
            var uut     = new AnythingActivator(DefaultRules.All.After(new ActivateInstances(myObject, myString)));
            var result1 = uut.New <Func <AClass> >();
            var result2 = uut.New <Func <string> >();

            //Debug
            xconsole.WriteLine(string.Join(Environment.NewLine, uut.LastErrorList));
            xconsole.WriteLine(string.Join(Environment.NewLine, uut.LastActivationTree));

            //
            Assert.That(result1, x => x() == myObject);
            Assert.That(result2, x => x() == myString);
        }
Beispiel #8
0
 public void AAFindsConcreteTypeEvenIfTheAssemblyIsntReferenced()
 {
     Assert.That(UnitUnderTest.Param1.GetType().Assembly.FullName.Contains("TestCases.ANotReferencedAssembly"));
 }
 public void AndMocksAnInterface__AssumingThatAKnownMockingFrameworkAssemblyWasFindable()
 {
     UnitUnderTest.Param4.ShouldBeAssignableTo <ICloneable>();
     Assert.That(CreateFromMock.IsAKnownMock(UnitUnderTest.Param4));
 }
 public void AndFindsConcreteTypeForINterfaceWithFakeInTestAssembly()
 {
     UnitUnderTest.Param2.ShouldBeAssignableTo <INterfaceWithFakeInTestAssembly>();
     Assert.That(UnitUnderTest.Param2.GetType().Assembly, Is.EqualTo(GetType().Assembly));
 }
 public void AndFindsConcreteTypeForInterfaceInAssembliesInBaseDirectoryEvenIfTheAssemblyIsntReferenced()
 {
     UnitUnderTest.Param3.ShouldBeAssignableTo <INterfaceWithClassInNotReferencedAssembly>();
     Assert.That(UnitUnderTest.Param3.GetType().Assembly.FullName.Contains("TestCases.ANotReferencedAssembly"));
 }
Beispiel #12
0
 public void Logs_ToSpecifiedLogger()
 {
     sut.Merge(new MemoryStream(new byte[0]), new Dictionary <string, string>());
     Assert.That(logger.LoggedLines, Is.NotEmpty);
 }
Beispiel #13
0
 public void AAFulfillsConstructorDependencyOnINterfaceWithFakeInTestAssembly()
 {
     UnitUnderTest.Param2.ShouldBeAssignableTo <INterfaceWithFakeInTestAssembly>();
     Assert.That(UnitUnderTest.Param2.GetType().Assembly, Is.EqualTo(GetType().Assembly));
 }