Example #1
0
 public static bool InterfaceTest4()
 {
     TestClassB tc = new TestClassB();
     IInterfaceA a = tc;
     bool result = (a.A() == 1);
     return result;
 }
Example #2
0
 public void MapTest()
 {
     ConfigurationMapper<TestClassA, TestClassB> target = new ConfigurationMapper<TestClassA, TestClassB>();
     TestClassA from = new TestClassA() { Name = "test" };
     TestClassB to = new TestClassB();
     target.Map(from, to);
     Assert.AreEqual(from.Name, to.InnerClassName);
 }
 public void MapAll_ValidInput_CallsMapper()
 {
     var mapperMock = A.Fake<IMapper<TestClassA, TestClassB>>();
     var target = new TestClassA[10];
     var output = new TestClassB[10];
     A.CallTo(() => mapperMock.MapMultiple(target)).Returns(output);
     IEnumerable<TestClassB> result = target.MapAll(mapperMock);
     Assert.AreEqual(output, result);
 }
Example #4
0
        public async Task MapTo_ValidInput_UsesProvidedMapper()
        {
            var source     = new TestClassC();
            var mapperMock = A.Fake <IExtensibleMapper <TestClassC, TestClassB> >();
            var expected   = new TestClassB();

            A.CallTo(() => mapperMock.Map((object)source)).Returns(expected);
            var actual = await source.MapToAsync <TestClassB>(mapperMock);

            Assert.AreEqual(expected, actual);
            MappingRepository.Default.Clear();
        }
Example #5
0
        public void ResolveRegisteredDependency_WithDependency_ReturnsInstantiatedObject()
        {
            var service = new DependencyService();

            service.Register <TestClassA>();
            service.Register <TestClassB>();

            TestClassB instance = service.Resolve <TestClassB>();

            Assert.NotNull(instance);
            Assert.IsInstanceOf <TestClassB>(instance);
        }
Example #6
0
        public void MapTo_ValidInputAndTarget_UsesProvidedMapper()
        {
            var source     = new TestClassC();
            var mapperMock = A.Fake <IExtensibleMapper <TestClassC, TestClassB> >();
            var expected   = new TestClassB();

            A.CallTo(() => mapperMock.Map(source, (object)expected)).Returns(expected);
            TestClassB actual = source.MapTo(expected, mapperMock);

            Assert.AreEqual(expected, actual);
            MappingRepository.Default.Clear();
        }
Example #7
0
        public void MapTest()
        {
            ConfigurationMapper <TestClassA, TestClassB> target = new ConfigurationMapper <TestClassA, TestClassB>();
            TestClassA from = new TestClassA()
            {
                Name = "test"
            };
            TestClassB to = new TestClassB();

            target.Map(from, to);
            Assert.AreEqual(from.Name, to.InnerClassName);
        }
Example #8
0
 public void ConvertTestComplex()
 {
     var target = new PropertyConverter();
     var source = new TestClassA {InnerClass = new TestClassC()};
     const string expected = "test";
     source.InnerClass.Name = expected;
     var fromProperty = typeof (TestClassA).GetProperty("InnerClass");
     var targetObject = new TestClassB {InnerClassName = "wrongstring"};
     var toProperty = typeof (TestClassB).GetProperty("InnerClassName");
     target.Convert(source, fromProperty, targetObject, toProperty);
     Assert.AreEqual(expected, targetObject.InnerClassName);
     Assert.AreEqual(expected, source.InnerClass.Name);
 }
Example #9
0
 public void ConvertTestSimple()
 {
     var target = new PropertyConverter();
     var source = new TestClassA();
     const string expected = "test";
     source.Name = expected;
     var fromProperty = typeof (TestClassA).GetProperty("Name");
     var targetObject = new TestClassB();
     targetObject.Name = "wrongstring";
     var toProperty = typeof (TestClassB).GetProperty("Name");
     target.Convert(source, fromProperty, targetObject, toProperty);
     Assert.AreEqual(expected, targetObject.Name);
     Assert.AreEqual(expected, source.Name);
 }
Example #10
0
        public void Test5()
        {
            var        parameter = Expression.Parameter(typeof(TestClassA));
            var        exp       = Expression.Lambda <Func <TestClassA, TestClassB> >(Expression.TypeAs(parameter, typeof(TestClassB)), parameter);
            var        f         = LambdaCompiler.Compile(exp, CompilerOptions.All);
            var        a         = new TestClassA();
            TestClassB b         = f(a);

            Assert.IsNull(b);
            b = new TestClassB();
            var bb = f(b);

            Assert.AreEqual(b, bb);
        }
        public void Given_PropertiesRelatedMainIntegerOtherStringNull_When_TryValidateObject_Then_FalseRetrieved()
        {
            var classObj          = new TestClassB {
            };
            var validationContext = new ValidationContext(classObj)
            {
                MemberName = nameof(TestClassA.TestString)
            };
            var validationResults = new List <ValidationResult>();

            var result = Validator.TryValidateObject(classObj, validationContext, validationResults, true);

            Assert.False(result);
        }
Example #12
0
        public void ComposedValuesTest()
        {
            var o = new TestClassB();

            SetRandom.Values(o);
            var x = o.C;
            var y = o.D.A;
            var z = o.D.B;

            SetRandom.Values(o);
            Assert.AreNotEqual(x, o.C);
            Assert.AreNotEqual(y, o.D.A);
            Assert.AreNotEqual(z, o.D.B);
        }
Example #13
0
 public void ConvertTestComplex()
 {
     PropertyConverter target = new PropertyConverter();
     TestClassA source = new TestClassA();
     source.InnerClass = new TestClassC();
     var expected = "test";
     source.InnerClass.Name = expected;
     PropertyInfo fromProperty = typeof(TestClassA).GetProperty("InnerClass");
     TestClassB targetObject = new TestClassB();
     targetObject.InnerClassName = "wrongstring";
     PropertyInfo toProperty = typeof(TestClassB).GetProperty("InnerClassName");
     target.Convert(source, fromProperty, targetObject, toProperty);
     Assert.AreEqual(expected, targetObject.InnerClassName);
     Assert.AreEqual(expected, source.InnerClass.Name);
 }
Example #14
0
        public async Task MapTo_ValidInputAndTarget_UsesProvidedRepo()
        {
            var source     = new TestClassC();
            var mapperMock = A.Fake <IExtensibleMapper <TestClassC, TestClassB> >();
            var expected   = new TestClassB();

            A.CallTo(() => mapperMock.Map(source, (object)expected)).Returns(expected);
            var repoMock = A.Fake <IMappingRepository>();

            A.CallTo(() => repoMock.ResolveMapper(typeof(TestClassC), typeof(TestClassB))).Returns(mapperMock);
            TestClassB actual = await source.MapToAsync(expected, repoMock);

            Assert.AreEqual(expected, actual);
            MappingRepository.Default.Clear();
        }
Example #15
0
        public void Map_NullInner_PropertySkipped()
        {
            var target    = new ConventionMapper <TestClassA, TestClassB>();
            var mapSource = new TestClassA
            {
                Name       = "TestName",
                Code       = 123,
                InnerClass = null, // this needs to be null for this scenario. Making it explicit here.
            };

            TestClassB result = target.Map(mapSource);

            Assert.IsNull(result.InnerClassName);
            Assert.AreEqual(mapSource.Name, result.Name);
        }
Example #16
0
        public void MapTo_ValidInput_UsesProvidedRepo()
        {
            var source     = new TestClassC();
            var mapperMock = A.Fake <IExtensibleMapper <TestClassC, TestClassB> >();
            var expected   = new TestClassB();

            A.CallTo(() => mapperMock.Map((object)source)).Returns(expected);
            var repoMock = A.Fake <IMappingRepository>();

            A.CallTo(() => repoMock.ResolveMapper(typeof(TestClassC), typeof(TestClassB))).Returns(mapperMock);
            var actual = source.MapTo <TestClassB>(repoMock);

            Assert.AreEqual(expected, actual);
            MappingRepository.Default.Clear();
        }
Example #17
0
        static public void ASubclassCanBeSerializedAndDeserialized()
        {
            TestClassB testClass = new TestClassB()
            {
                someId         = CONST_GUID,
                someFloatData  = 0.2771f,
                someStringData = "there's a string here"
            };

            string serialized = Serializer.Write <TestClassA>(testClass, OutputOptions.None, Serializer.Format.JSON);

            TestClassA a = Serializer.Read <TestClassA>(serialized);

            Assert.IsInstanceOf(typeof(TestClassB), a);
        }
Example #18
0
        public void TestCopyToExistingObject()
        {
            TestClassA a = new TestClassA()
            {
                TestClassC = new TestClassC()
                {
                    MyProperty = "string"
                },
                List = new List <TestClassC>()
                {
                    new TestClassC()
                    {
                        MyProperty = "cstring"
                    },
                    new TestClassC()
                    {
                        MyProperty = "cstring"
                    },
                },
                MyProperty = "string",
                Array      = new[]
                {
                    new TestClassC()
                    {
                        MyProperty = "string",
                        Obj        = new TestClassD()
                        {
                            MyProperty = "sstring"
                        }
                    },
                    new TestClassC()
                    {
                        MyProperty = "string",
                        Obj        = new TestClassD()
                        {
                            MyProperty = "sstring"
                        }
                    },
                }
            };
            var b = new TestClassB();

            a.MapTo(b);
            Assert.Equal(a.MyProperty, b.MyProperty);
            Assert.Equal(a.TestClassC.MyProperty, b.TestClassC.MyProperty);
            Assert.Equal(a.List.Count, b.List.Count);
            Assert.Equal(a.Array.Length, b.Array.Length);
        }
Example #19
0
        public void PropertyConverterNegativeTest()
        {
            PropertyConverter target = new PropertyConverter();
            var source         = new TestClassA();
            var sourceProperty = source.GetType().GetProperty("InnerClass");
            var result         = new TestClassB();
            var resultProperty = result.GetType().GetProperty("InnerClassCode");

            source.InnerClass = new TestClassC();
            target.Convert(
                source,
                sourceProperty,
                target,
                resultProperty,
                false);
        }
Example #20
0
        public async Task GivenRegistryWithMultiplePipes_WhenResolvingFromAToD_ItShouldChainAllThePipes()
        {
            for (int counter = 0; counter < 15; counter++)
            {
                // pre-arrange
                var instanceClassA = new TestClassA();
                var instanceClassB = new TestClassB();
                var instanceClassC = new TestClassC();
                var instanceClassD = new TestClassD();

                // arrange
                var semanticBuilder = new SemanticBuilder();

                var enrollmentList = new List <Action>
                {
                    () => semanticBuilder.InstallPipe <TestClassA, TestClassB>((a, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassA, a);
                        return(instanceClassB);
                    }),
                    () => semanticBuilder.InstallPipe <TestClassB, TestClassC>((b, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassB, b);
                        return(instanceClassC);
                    }),
                    () => semanticBuilder.InstallPipe <TestClassC, TestClassD>((c, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassC, c);
                        return(instanceClassD);
                    }),
                };

                var enrollmentActions = enrollmentList.OrderBy(x => Guid.NewGuid());
                foreach (var enrollmentAction in enrollmentActions)
                {
                    enrollmentAction();
                }

                ISemanticBroker broker = semanticBuilder.CreateBroker();

                // act
                var solvedExecution = await broker.On(instanceClassA).Output <TestClassD>();

                // assert
                Assert.AreEqual(instanceClassD, solvedExecution);
            }
        }
        public async Task GivenRegistryWithMultiplePipes_WhenResolvingFromAToD_ItShouldChainAllThePipes()
        {
            for (int counter = 0; counter < 15; counter++)
            {
                // pre-arrange
                var instanceClassA = new TestClassA();
                var instanceClassB = new TestClassB();
                var instanceClassC = new TestClassC();
                var instanceClassD = new TestClassD();

                // arrange
                var semanticBuilder = new SemanticBuilder();

                var enrollmentList = new List<Action>
                {
                    () => semanticBuilder.InstallPipe<TestClassA, TestClassB>((a, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassA, a);
                        return instanceClassB;
                    }),
                    () => semanticBuilder.InstallPipe<TestClassB, TestClassC>((b, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassB, b);
                        return instanceClassC;
                    }),
                    () => semanticBuilder.InstallPipe<TestClassC, TestClassD>((c, innerBroker) =>
                    {
                        Assert.AreSame(instanceClassC, c);
                        return instanceClassD;
                    }),
                };

                var enrollmentActions = enrollmentList.OrderBy(x=>Guid.NewGuid());
                foreach (var enrollmentAction in enrollmentActions)
                {
                    enrollmentAction();
                }

                ISemanticBroker broker = semanticBuilder.CreateBroker();

                // act
                var solvedExecution = await broker.On(instanceClassA).Output<TestClassD>();

                // assert
                Assert.AreEqual(instanceClassD, solvedExecution);
            }
        }
        public async Task GivenBrokerWithPipeFromObjectAToObjectB_WhenResolving_ItShouldInstantiateThePipe()
        {
            // pre-arrangement
            var expectedOutputObject = new TestClassB();

            // arrangement
            var builder = new SemanticBuilder();
            builder.InstallPipe<TestClassA, TestClassB>((a, innerBroker) => expectedOutputObject);

            ISemanticBroker broker = builder.CreateBroker();

            // act
            var actualOutputObject = await broker.On(new TestClassA()).Output<TestClassB>();

            // assert
            Assert.AreSame(expectedOutputObject, actualOutputObject);
        }
Example #23
0
        public void ConvertTestSimple()
        {
            PropertyConverter target = new PropertyConverter();
            TestClassA        source = new TestClassA();
            var expected             = "test";

            source.Name = expected;
            PropertyInfo fromProperty = typeof(TestClassA).GetProperty("Name");
            TestClassB   targetObject = new TestClassB();

            targetObject.Name = "wrongstring";
            PropertyInfo toProperty = typeof(TestClassB).GetProperty("Name");

            target.Convert(source, fromProperty, targetObject, toProperty);
            Assert.AreEqual(expected, targetObject.Name);
            Assert.AreEqual(expected, source.Name);
        }
Example #24
0
        public void AddMapping_MockedInternalMappers_Redirects()
        {
            BaseMapper <TestClassB, TestClassD>[] mapperMocks =
                A.CollectionOfFake <BaseMapper <TestClassB, TestClassD> >(5).ToArray();
            var extMock = A.Fake <BaseMapper <TestClassB, TestClassD> >(
                o => o.Implements(typeof(IExtensibleMapper <TestClassB, TestClassD>)));
            var        results = new List <IEnumerable <MemberMappingInfo <TestClassB, TestClassD> > >();
            Randomizer rnd     = Randomizer.GetRandomizer(typeof(CompositeMapper <,>).GetMethod("AddMapping"));
            int        extPos  = rnd.Next(mapperMocks.Length);

            for (int i = 0; i < mapperMocks.Length; ++i)
            {
                var res = new[]
                {
                    A.Fake <MemberMappingInfo <TestClassB, TestClassD> >(
                        o => o.WithArgumentsForConstructor(
                            new object[]
                    {
                        Guid.NewGuid().ToString(),
                        Guid.NewGuid().ToString()
                    }))
                };

                if (i == extPos)
                {
                    mapperMocks[i] = extMock;
                }

                results.Add(res);
                A.CallTo(() => mapperMocks[i].GetMappings())
                .Returns(res);
            }

            var target = new CompositeMapper <TestClassB, TestClassD>(mapperMocks);
            var source = new TestClassB();
            var result = new TestClassD();
            MappingAction <TestClassB, TestClassD> action = (s, t) => t.SomeOtherName = s.Name;

            target.AddMappingAction("foo", "bar", action);

            target.ExtensibleMapper.ShouldBeSameAs(extMock);
            A.CallTo(() =>
                     ((IExtensibleMapper <TestClassB, TestClassD>)extMock).AddMappingAction("foo", "bar", action))
            .MustHaveHappened();
        }
Example #25
0
        public async Task GivenBrokerWithPipeFromObjectAToObjectB_WhenResolving_ItShouldInstantiateThePipe()
        {
            // pre-arrangement
            var expectedOutputObject = new TestClassB();

            // arrangement
            var builder = new SemanticBuilder();

            builder.InstallPipe <TestClassA, TestClassB>((a, innerBroker) => expectedOutputObject);

            ISemanticBroker broker = builder.CreateBroker();

            // act
            var actualOutputObject = await broker.On(new TestClassA()).Output <TestClassB>();

            // assert
            Assert.AreSame(expectedOutputObject, actualOutputObject);
        }
Example #26
0
        public void ConvertTestComplex()
        {
            var target = new PropertyConverter();
            var source = new TestClassA {
                InnerClass = new TestClassC()
            };
            const string expected = "test";

            source.InnerClass.Name = expected;
            var fromProperty = typeof(TestClassA).GetProperty("InnerClass");
            var targetObject = new TestClassB {
                InnerClassName = "wrongstring"
            };
            var toProperty = typeof(TestClassB).GetProperty("InnerClassName");

            target.Convert(source, fromProperty, targetObject, toProperty);
            Assert.AreEqual(expected, targetObject.InnerClassName);
            Assert.AreEqual(expected, source.InnerClass.Name);
        }
Example #27
0
        public void AddMapping_MockedInternalMappers_Redirects()
        {
            var mapperMocks = A.CollectionOfFake<BaseMapper<TestClassB, TestClassD>>(5).ToArray();
            var extMock = A.Fake<BaseMapper<TestClassB, TestClassD>>(
                o => o.Implements(typeof(IExtensibleMapper<TestClassB, TestClassD>)));
            var results = new List<IEnumerable<MemberMappingInfo<TestClassB, TestClassD>>>();
            var rnd = NUnit.Framework.Randomizer.GetRandomizer(typeof(CompositeMapper<,>).GetMethod("AddMapping"));
            var extPos = rnd.Next(mapperMocks.Length);
            for (int i = 0; i < mapperMocks.Length; ++i)
            {
                var res = new MemberMappingInfo<TestClassB, TestClassD>[]
                {
                    A.Fake<MemberMappingInfo<TestClassB, TestClassD>>(
                        o => o.WithArgumentsForConstructor(
                            new object[]
                            {
                                Guid.NewGuid().ToString(),
                                Guid.NewGuid().ToString()
                            }))
                };

                if (i == extPos)
                {
                    mapperMocks[i] = extMock;
                }

                results.Add(res);
                A.CallTo(() => mapperMocks[i].GetMappings())
                    .Returns(res);
            }

            var target = new CompositeMapper<TestClassB, TestClassD>(mapperMocks);
            var source = new TestClassB();
            var result = new TestClassD();
            MappingAction<TestClassB, TestClassD> action = (s, t) => t.SomeOtherName = s.Name;
            target.AddMappingAction("foo", "bar", action);

            target.ExtensibleMapper.ShouldBeSameAs(extMock);
            A.CallTo(() =>
                ((IExtensibleMapper<TestClassB, TestClassD>)extMock).AddMappingAction("foo", "bar", action))
                .MustHaveHappened();
        }
Example #28
0
        public void LocalizeItem_PropertyHasDifferentCasesAndUpperCaseIsRequested_LocalizesAllProperties()
        {
            const string firstLanguageCode  = "EN";
            const string secondLanguageCode = "En";
            const string thirdLanguageCode  = "eN";
            const string fourthLanguageCode = "en";

            var contentsOne = new[]
            {
                new LocalizedContent(firstLanguageCode, "this is english content"),
                new LocalizedContent(secondLanguageCode, "this is another content")
            };

            var contentsTwo = new[]
            {
                new LocalizedContent(thirdLanguageCode, "this is english content"),
                new LocalizedContent(fourthLanguageCode, "this is another content")
            };

            var firstObj = new TestClassB
            {
                PropertyA = contentsOne.First().Serialize(),
                PropertyB = contentsOne.Last().Serialize()
            };

            var secondObj = new TestClassB
            {
                PropertyA = contentsTwo.First().Serialize(),
                PropertyB = contentsTwo.Last().Serialize()
            };

            const string localizationRequestLanguage = "EN";

            firstObj.Localize(localizationRequestLanguage);
            secondObj.Localize(localizationRequestLanguage);

            Assert.Equal("this is english content", firstObj.PropertyA);
            Assert.Equal("this is another content", firstObj.PropertyB);
            Assert.Equal("this is english content", secondObj.PropertyA);
            Assert.Equal("this is another content", secondObj.PropertyB);
        }
Example #29
0
        public void JsonSerializeTest()
        {
            var testClassB = new TestClassB()
            {
                intvalue    = 5,
                stringvalue = "testclassB",
            };

            var testClassA = new TestClassA()
            {
                intvalue    = 3,
                stringvalue = "testclassA",
                classB      = testClassB,
            };

            var serializedJson = JsonUtility.ToJson(testClassA);
            var test           = JsonUtility.FromJson <TestClassA>(serializedJson);

            Assert.AreEqual(test.stringvalue, "testclassA");
            Assert.AreEqual(test.classB.stringvalue, "testclassB");
        }
Example #30
0
        public async Task GivenRegistration_WhenTheProcessDelegateIsCalled_ItShouldExecuteTheSpecifiedGenericCallback()
        {
            // pre-arrangement
            var expectedTestClassA = new TestClassA();
            var expectedTestClassB = new TestClassB();

            // arrange
            var semanticBuilder = new SemanticBuilder();

            semanticBuilder.InstallPipe <TestClassA, TestClassB>((a, innerBroker) =>
            {
                Assert.AreSame(expectedTestClassA, a);
                return(expectedTestClassB);
            });
            ISemanticBroker semanticBroker = semanticBuilder.CreateBroker();

            // act
            var processedOuput = await semanticBroker.On(expectedTestClassA).Output <TestClassB>();

            // assert
            Assert.AreSame(expectedTestClassB, processedOuput);
        }
        public async Task GivenRegistryWithMultipleSources_WhenResolvingToSpecificType_ItShouldResolve()
        {
            // pre-arrange
            var instanceClassA = new TestClassA();
            var instanceClassB = new TestClassB();
            var instanceClassC = new TestClassC();

            // arrange
            var semanaticBuilder = new SemanticBuilder();
            semanaticBuilder.InstallPipe<TestClassA, TestClassB>((a, semanticBroker) => instanceClassB);
            semanaticBuilder.InstallPipe<TestClassA, TestClassC>((a, semanticBroker) => instanceClassC);

            ISemanticBroker broker = semanaticBuilder.CreateBroker();

            // act
            var solveToB = await broker.On(instanceClassA).Output<TestClassB>();
            var solveToC = await broker.On(instanceClassA).Output<TestClassC>();

            // assert
            Assert.AreEqual(instanceClassB, solveToB);
            Assert.AreEqual(instanceClassC, solveToC);
        }
        public async Task GivenRegistration_WhenTheProcessDelegateIsCalled_ItShouldExecuteTheSpecifiedGenericCallback()
        {
            // pre-arrangement
            var expectedTestClassA = new TestClassA();
            var expectedTestClassB = new TestClassB();

            // arrange
            var semanticBuilder = new SemanticBuilder();

            semanticBuilder.InstallPipe<TestClassA, TestClassB>((a, innerBroker) =>
            {
                Assert.AreSame(expectedTestClassA, a);
                return expectedTestClassB;
            });
            ISemanticBroker semanticBroker = semanticBuilder.CreateBroker();

            // act
            var processedOuput = await semanticBroker.On(expectedTestClassA).Output<TestClassB>();

            // assert
            Assert.AreSame(expectedTestClassB, processedOuput);
        }
Example #33
0
        public void TestRemovedProperty()
        {
            var b = new TestClassB {
                S = "zzz"
            };
            var a = new TestClassA {
                B = b, ArrayB = new[] { b }, S = "zzz"
            };

            a.A = a;
            var data = serializer.Serialize(a);

            Console.WriteLine(data.Length);
            var aa = serializer.Deserialize <TestClassAChanged>(data);

            Assert.AreSame(aa, aa.A);
            Assert.IsNotNull(aa.ArrayB);
            Assert.AreEqual(1, aa.ArrayB.Length);
            Assert.AreEqual("zzz", aa.S);
            Assert.IsNotNull(aa.ArrayB[0]);
            Assert.AreEqual("zzz", aa.ArrayB[0].S);
        }
Example #34
0
        public void MapTest()
        {
            var target = new ConventionMapper<TestClassA, TestClassB>();
            var from = new TestClassA();
            var to = new TestClassB();
            from.Code = 123;
            string expectedName = "Test123";
            from.Name = expectedName;
            from.InnerClass = new TestClassC();
            string expectedInnerName = "InnerName234";
            double expectedInnerFraction = Math.PI;
            from.InnerClass.Name = expectedInnerName;
            from.InnerClass.Fraction = expectedInnerFraction;
            target.Map(from, to);
            Assert.AreEqual(expectedName, to.Name);
            Assert.AreEqual(expectedInnerName, to.InnerClassName);
            Assert.AreEqual(expectedInnerFraction, to.InnerClassFraction);

            // making sure the mapping didn't mess with the "sourceMember" object.
            Assert.AreEqual(expectedName, from.Name);
            Assert.AreEqual(expectedInnerName, from.InnerClass.Name);
            Assert.AreEqual(expectedInnerFraction, from.InnerClass.Fraction);
        }
Example #35
0
        public async Task GivenRegistryWithOnePipes_WhenResolvingFromAToB_ItShouldCallIt()
        {
            // pre-arrange
            var instanceClassA = new TestClassA();
            var instanceClassB = new TestClassB();

            // arrange
            var semanaticBuilder = new SemanticBuilder();

            semanaticBuilder.InstallPipe <TestClassA, TestClassB>((a, semanticBroker) =>
            {
                Assert.AreSame(instanceClassA, a);
                return(instanceClassB);
            });

            ISemanticBroker broker = semanaticBuilder.CreateBroker();

            // act
            var solvedExecution = await broker.On(instanceClassA).Output <TestClassB>();

            // assert
            Assert.AreEqual(instanceClassB, solvedExecution);
        }
Example #36
0
        public void JsonPersistentSaveTest()
        {
            var testClassB = new TestClassB()
            {
                intvalue    = 5,
                stringvalue = "testclassB",
            };

            var testClassA = new TestClassA()
            {
                intvalue    = 3,
                stringvalue = "testclassA",
                classB      = testClassB,
            };

            string line = "";

            PersistentData.SaveToJson(testClassA);
            var a    = PersistentData.LoadFromJson <TestClassA>();
            var test = JsonUtility.FromJson <TestClassA>(line);

            Assert.AreEqual(a.classB.stringvalue, "testclassB");
            PersistentData.Delete <TestClassA>();
        }
Example #37
0
        public async Task GivenRegistryWithMultipleSources_WhenResolvingToSpecificType_ItShouldResolve()
        {
            // pre-arrange
            var instanceClassA = new TestClassA();
            var instanceClassB = new TestClassB();
            var instanceClassC = new TestClassC();

            // arrange
            var semanaticBuilder = new SemanticBuilder();

            semanaticBuilder.InstallPipe <TestClassA, TestClassB>((a, semanticBroker) => instanceClassB);
            semanaticBuilder.InstallPipe <TestClassA, TestClassC>((a, semanticBroker) => instanceClassC);

            ISemanticBroker broker = semanaticBuilder.CreateBroker();

            // act
            var solveToB = await broker.On(instanceClassA).Output <TestClassB>();

            var solveToC = await broker.On(instanceClassA).Output <TestClassC>();

            // assert
            Assert.AreEqual(instanceClassB, solveToB);
            Assert.AreEqual(instanceClassC, solveToC);
        }
Example #38
0
 public TestClassC(TestClassA testClassA, TestClassB testClassB, TestClassD testClassD)
 {
     this.TestClassA = testClassA;
     this.TestClassB = testClassB;
     this.TestClassD = testClassD;
 }
 public void Init()
 {
     objectA1 = new TestClassA();
     objectA2 = new TestClassA();
     objectB = new TestClassB();
 }
Example #40
0
 public async Task MapTo_ValidInputAndTarget_UsesProvidedMapper()
 {
     var source = new TestClassC();
     var mapperMock = A.Fake<IExtensibleMapper<TestClassC, TestClassB>>();
     var expected = new TestClassB();
     A.CallTo(() => mapperMock.Map(source, (object) expected)).Returns(expected);
     TestClassB actual = await source.MapToAsync(expected, mapperMock);
     Assert.AreEqual(expected, actual);
     MappingRepository.Default.Clear();
 }
Example #41
0
        public void Map_MockedInternalMappers_Redirects()
        {
            BaseMapper<TestClassB, TestClassD>[] mapperMocks =
                A.CollectionOfFake<BaseMapper<TestClassB, TestClassD>>(5).ToArray();
            var results = new List<IEnumerable<MemberMappingInfo<TestClassB, TestClassD>>>();
            for (int i = 0; i < mapperMocks.Length; ++i)
            {
                var res = new[]
                {
                    A.Fake<MemberMappingInfo<TestClassB, TestClassD>>(
                        o => o.WithArgumentsForConstructor(
                            new object[]
                            {
                                Guid.NewGuid().ToString(),
                                Guid.NewGuid().ToString()
                            }))
                };

                results.Add(res);
                A.CallTo(() => mapperMocks[i].GetMappings())
                    .Returns(res);
            }

            var target = new CompositeMapper<TestClassB, TestClassD>(mapperMocks);
            var source = new TestClassB();
            var result = new TestClassD();

            target.Map(source, result);

            foreach (var m in results.SelectMany(e => e))
            {
                A.CallTo(() => m.Map(source, result)).MustHaveHappened();
            }
        }
Example #42
0
 public void MapTo_ValidInput_UsesProvidedMapper()
 {
     var source = new TestClassC();
     var mapperMock = A.Fake<IExtensibleMapper<TestClassC, TestClassB>>();
     var expected = new TestClassB();
     A.CallTo(() => mapperMock.Map((object) source)).Returns(expected);
     var actual = source.MapTo<TestClassB>(mapperMock);
     Assert.AreEqual(expected, actual);
     MappingRepository.Default.Clear();
 }
Example #43
0
 public async Task MapTo_ValidInput_UsesProvidedRepo()
 {
     var source = new TestClassC();
     var mapperMock = A.Fake<IExtensibleMapper<TestClassC, TestClassB>>();
     var expected = new TestClassB();
     A.CallTo(() => mapperMock.Map((object) source)).Returns(expected);
     var repoMock = A.Fake<IMappingRepository>();
     A.CallTo(() => repoMock.ResolveMapper(typeof (TestClassC), typeof (TestClassB))).Returns(mapperMock);
     var actual = await source.MapToAsync<TestClassB>(repoMock);
     Assert.AreEqual(expected, actual);
     MappingRepository.Default.Clear();
 }
Example #44
0
 public async Task MapTo_NullTarget_Throws_3()
 {
     var source = new TestClassB();
     await source.MapToAsync((TestClassC) null, A.Fake<IMappingRepository>());
 }
Example #45
0
 public void MapTo_NullTarget_Throws_3()
 {
     var source = new TestClassB();
     source.MapTo((TestClassC) null, A.Fake<IMappingRepository>());
 }
Example #46
0
 public void MapTo_NullTarget_Throws_1()
 {
     var source = new TestClassB();
     source.MapTo((TestClassC) null);
 }
Example #47
0
 public void MapTo_NullTarget_Throws_2()
 {
     var source = new TestClassB();
     source.MapTo((TestClassC) null, A.Fake<IMapper>());
 }
Example #48
0
 private void CheckMapping(TestClassA source, TestClassB target)
 {
     Assert.AreEqual(source.Name, target.Name);
     Assert.AreEqual(source.InnerClass.Name, target.InnerClassName);
     Assert.AreEqual(source.InnerClass.Fraction, target.InnerClassFraction);
 }
Example #49
0
 public void MapTo_ValidInputAndTarget_UsesProvidedRepo()
 {
     var source = new TestClassC();
     var mapperMock = A.Fake<IExtensibleMapper<TestClassC, TestClassB>>();
     var expected = new TestClassB();
     A.CallTo(() => mapperMock.Map(source, (object) expected)).Returns(expected);
     var repoMock = A.Fake<IMappingRepository>();
     A.CallTo(() => repoMock.ResolveMapper(typeof (TestClassC), typeof (TestClassB))).Returns(mapperMock);
     TestClassB actual = source.MapTo(expected, repoMock);
     Assert.AreEqual(expected, actual);
     MappingRepository.Default.Clear();
 }
Example #50
0
 public void Map_WithFactory_MappingWorks()
 {
     var target = new ConventionMapper<TestClassA, TestClassB>();
     TestClassA source = GenerateSource();
     var result = new TestClassB();
     target.Map((object) source, () => result);
     CheckMapping(source, result);
 }
Example #51
0
 public TestClassAutoC(TestClassA testClassA, TestClassB testClassB)
 {
     this.TestClassA = testClassA;
     this.TestClassB = testClassB;
 }
Example #52
0
 public async Task MapTo_NullTarget_Throws_1()
 {
     var source = new TestClassB();
     await source.MapToAsync((TestClassC) null);
 }
        public async Task GivenRegistryWithOnePipes_WhenResolvingFromAToB_ItShouldCallIt()
        {
            // pre-arrange
            var instanceClassA = new TestClassA();
            var instanceClassB = new TestClassB();

            // arrange
            var semanaticBuilder = new SemanticBuilder();
            semanaticBuilder.InstallPipe<TestClassA, TestClassB>((a, semanticBroker) =>
            {
                Assert.AreSame(instanceClassA, a);
                return instanceClassB;
            });

            ISemanticBroker broker = semanaticBuilder.CreateBroker();

            // act
            var solvedExecution = await broker.On(instanceClassA).Output<TestClassB>();

            // assert
            Assert.AreEqual(instanceClassB, solvedExecution);
        }
Example #54
0
 public TestClassB createObj()
 {
     obj = new TestClassB();
     return(obj);
 }
Example #55
0
        public void MapTo_NullTarget_Throws_1()
        {
            var source = new TestClassB();

            source.MapTo((TestClassC)null);
        }
Example #56
0
        public void MapTo_NullTarget_Throws_2()
        {
            var source = new TestClassB();

            source.MapTo((TestClassC)null, A.Fake <IMapper>());
        }
Example #57
0
 private void CheckMapping(TestClassA source, TestClassB target)
 {
     Assert.AreEqual(source.Name, target.Name);
     Assert.AreEqual(source.InnerClass.Name, target.InnerClassName);
     Assert.AreEqual(source.InnerClass.Fraction, target.InnerClassFraction);
 }
Example #58
0
        public void MapTo_NullTarget_Throws_3()
        {
            var source = new TestClassB();

            source.MapTo((TestClassC)null, A.Fake <IMappingRepository>());
        }
Example #59
0
 public void Map_NonGeneric_MappingWorks()
 {
     var target = new ConventionMapper<TestClassA, TestClassB>();
     TestClassA source = GenerateSource();
     var result = new TestClassB();
     target.Map(source, (object) result);
     CheckMapping(source, result);
 }
Example #60
0
 public void PropertyConverterNegativeTest()
 {
     var target = new PropertyConverter();
     var source = new TestClassA();
     var sourceProperty = source.GetType().GetProperty("InnerClass");
     var result = new TestClassB();
     var resultProperty = result.GetType().GetProperty("InnerClassCode");
     source.InnerClass = new TestClassC();
     target.Convert(
         source,
         sourceProperty,
         target,
         resultProperty,
         false);
 }