Beispiel #1
0
        public Program(IOptions <MySettings> optionsSettings, MySettings settings, IRuleSet <MyModel> ruleset, ITransformationManager transformer)
        {
            // Data transformations
            TransformSourceData sourceData = new TransformSourceData()
            {
                Word       = "Development",
                SourceTime = DateTime.Now,
                WordCount  = 100
            };

            TransformDestinationData destinationData =
                transformer.Transform <TransformSourceData, TransformDestinationData>(sourceData);

            foreach (var timeWord in destinationData.TimeWords)
            {
                Console.WriteLine("Time word: {0}", timeWord);
            }

            // Rule validations
            var model1 = new MyModel();
            var model2 = new MyModel
            {
                Name   = "brazil",
                Number = 34
            };

            var result1 = ruleset.Check(model1);
            var result2 = ruleset.ByDefaultCategory().Check(model1);
            var result3 = ruleset.ByCategory("critical").Check(model1);
            var result4 = ruleset.ByCode("RN-001").Check(model1);
            var result5 = ruleset.ByCode(new[] { "RN-002", "RN-004" }).Check(model1);
            var result6 = ruleset.ByDefaultCategory().Check(model2);
            var result7 = ruleset.ByCategory("critical").Check(model2);

            Assert(result1 != null, "result != null");
            Assert(!result1.IsSuccess, "!result.IsSuccess");
            Assert(result1.Unconformities != null, "result.Unconformities != null");
            Assert(result1.Unconformities.Count == 4, "result.Unconformities.Count == 4");
            Assert(string.Join(" ", result2.Unconformities.Keys) == "RN-001 RN-002",
                   "RN-001 RN-002");
            Assert(string.Join(" ", result3.Unconformities.Keys) == "RN-003 RN-004",
                   "RN-003 RN-004");
            Assert(string.Join(" ", result4.Unconformities.Keys) == "RN-001", "RN-001");
            Assert(string.Join(" ", result5.Unconformities.Keys) == "RN-002 RN-004",
                   "RN-002 RN-004");
            Assert(result6.IsSuccess, "result6.IsSuccess");
            Assert(!result7.IsSuccess, "!result7.IsSuccess");
            Assert(string.Join(" ", result7.Unconformities.Keys) == "RN-003 RN-004",
                   "RN-003 RN-004 (result7)");
        }
Beispiel #2
0
        public Program(ITransformationManager transformer)
        {
            var a = new A
            {
                AMessage = "Original message from A"
            };

            var b = new B
            {
                BMessage = "Original message from B"
            };

            var c = new C
            {
                CMessage = "Original message from C"
            };

            var listOfA = new List <A>
            {
                new A {
                    AMessage = "Message A1"
                },
                new A {
                    AMessage = "Message A2"
                },
                new A {
                    AMessage = "Message A3"
                },
            };

            var paginatedListOfA = new PaginatedResult <A>(new List <A>
            {
                new A {
                    AMessage = "Paginated A1"
                },
                new A {
                    AMessage = "Paginated A2"
                },
                new A {
                    AMessage = "Paginated A3"
                },
            }, 10, 3, 1000);

            var aFromB   = transformer.Transform <B, A>(b);
            var aFromC   = transformer.Transform <C, A>(c);
            var bFromA   = transformer.Transform <A, B>(a);
            var bFromC   = transformer.Transform <C, B>(c);
            var cFromA   = transformer.Transform <A, C>(a);
            var cFromAv1 =
                transformer.Transform <A, C, TransformerVariant>(a, TransformerVariant.Variant1);
            var cFromAv2 =
                transformer.Transform <A, C, TransformerVariant>(a, TransformerVariant.Variant2);
            var cFromAv3 =
                transformer.Transform <A, C, TransformerVariant>(a, TransformerVariant.Variant3);
            var cFromB           = transformer.Transform <B, C>(b);
            var listOfB          = transformer.Transform <A, B>(listOfA);
            var paginatedListOfB = transformer.Transform <A, B>(paginatedListOfA);
            var autoTransformerA = transformer.AutoTransform <TransformerFrom, AutoTransformerTo>(
                new TransformerFrom
            {
                ValueInteger = 1,
                ValueDecimal = 1.2m,
                ValueString  = "String qualquer",
                ValueEnum    = TransformerVariant.Variant2,
                ValueGuid    = Guid.NewGuid(),
                ValueClass   = new A {
                    AMessage = "A message from inner class"
                }
            });
            var autoTransformerB = transformer.AutoTransform <AutoTransformerFrom, AutoTransformerTo>(
                new AutoTransformerFrom
            {
                ValueInteger = 2,
                ValueDecimal = 2.3m,
                ValueString  = "String que pode ser copiada",
                ValueEnum    = TransformerVariant.Variant3,
                ValueGuid    = Guid.NewGuid(),
                ValueClass   = new A {
                    AMessage = "A message from inner class"
                }
            });

            Debug.Assert(aFromB.AMessage.Equals(b.BMessage), "Invalid aFromB");
            Debug.Assert(aFromC.AMessage.Equals(c.CMessage), "Invalid aFromC");
            Debug.Assert(bFromA.BMessage.Equals(a.AMessage), "Invalid bFromA");
            Debug.Assert(bFromC.BMessage.Equals(c.CMessage), "Invalid bFromC");
            Debug.Assert(cFromA.CMessage.Equals(a.AMessage), "Invalid cFromA");
            Debug.Assert(cFromAv1.CMessage.Equals(a.AMessage + "/Variant1"),
                         "Invalid cFromA/Variant1");
            Debug.Assert(cFromAv2.CMessage.Equals(a.AMessage + "/Variant2"),
                         "Invalid cFromA/Variant2");
            Debug.Assert(cFromAv3.CMessage.Equals(a.AMessage + "/Variant3"),
                         "Invalid cFromA/Variant3");
            Debug.Assert(cFromB.CMessage.Equals(b.BMessage), "Invalid cFromB");
            Debug.Assert(listOfB != null, "List of B is null");
            Debug.Assert(listOfB.Count() == listOfA.Count, "Invalid count of list B");
            Debug.Assert(paginatedListOfB.CurrentPage == paginatedListOfA.CurrentPage,
                         "Invalid CurrentPage of paginatedListOfB");
            Debug.Assert(paginatedListOfB.Limit == paginatedListOfA.Limit,
                         "Invalid Limit of paginatedListOfB");
            Debug.Assert(paginatedListOfB.NextPage == paginatedListOfA.NextPage,
                         "Invalid NextPage of paginatedListOfB");
            Debug.Assert(paginatedListOfB.Offset == paginatedListOfA.Offset,
                         "Invalid Offset of paginatedListOfB");
            Debug.Assert(paginatedListOfB.PageCount == paginatedListOfA.PageCount,
                         "Invalid OfPageCountfset of paginatedListOfB");
            Debug.Assert(paginatedListOfB.PreviousPage == paginatedListOfA.PreviousPage,
                         "Invalid PreviousPage of paginatedListOfB");
            Debug.Assert(paginatedListOfB.Total == paginatedListOfA.Total,
                         "Invalid Total of paginatedListOfB");
            Debug.Assert(paginatedListOfB.Result == null, "Invalid Result of paginatedListOfB");

            foreach (var(item, index) in listOfA.Select((item, index) => (item, index)))
            {
                Debug.Assert(item.AMessage.Equals(listOfB.ElementAt(index).BMessage),
                             "Invalid item pair value");
            }

            foreach (var(item, index) in paginatedListOfA.Result.Select((item, index) =>
                                                                        (item, index)))
            {
                Debug.Assert(
                    item.AMessage.Equals(paginatedListOfB.Result.ElementAt(index).BMessage),
                    "Invalid paginated item pair value");
            }
        }