Exemplo n.º 1
0
        public async Task ShouldReturnTrueForSameContextComparison()
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test1");
            SampleContext ctx2 = xmlFileCtx.InputContext("test1");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(true);
        }
        public async Task ShouldReturnTrueForSameContextComparison()
        {
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test1");
            SampleContext ctx2 = xmlFileCtx.InputContext("test1");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(true);

        }
Exemplo n.º 3
0
        public async Task ShouldReturnFalseForContextWithEntryContainingDifferentValues()
        {
            XmlFileContext <SampleContext> xmlFileCtx         = new XmlFileContext <SampleContext>(this.GetType());
            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test2");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test2");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
            result.Differences.Count.ShouldBe(2);

            result.Differences[0].ObjectId.ShouldBe("2");
            result.Differences[0].ObjectName.ShouldBe("Post");
            result.Differences[0].PropertyName.ShouldBe("Subject");
            result.Differences[0].ActualPropertyContent.ShouldBe("First Text");
            result.Differences[0].ExpectedPropertyContent.ShouldBe("First Text Modified");
            result.Differences[0].ToString().ShouldBe("Post.Subject Should be [First Text Modified] but was [First Text] - object with Post_Id : 2");

            result.Differences[1].ObjectId.ShouldBe("2");
            result.Differences[1].ObjectName.ShouldBe("Post");
            result.Differences[1].PropertyName.ShouldBe("Body");
            result.Differences[1].ActualPropertyContent.ShouldBe("Some Text here");
            result.Differences[1].ExpectedPropertyContent.ShouldBe("Some Other Text here");
        }
Exemplo n.º 4
0
        private SampleContext GetInputContext(string testname)
        {
            XmlFileContext <SampleContext> factory = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx = factory.InputContext(testname, "persistent_tests_input", false);

            return(ctx);
        }
        public async Task ShouldReturnFalseForContextWithMissingEntryinExpected()
        {
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());

            XmlFileContext<SampleContext> xmlFileExpectedCtx = new XmlFileContext<SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test1");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test1");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
        }
Exemplo n.º 6
0
        public async Task ShouldReturnFalseForContextWithMissingEntryinExpected()
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test1");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test1");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
        }
        public async Task TestWithXmlFIles()
        {
            //load a context
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());

            using (SampleContext ctx = xmlFileCtx.InputContext("test1"))
            {
                string fromFile = await ctx.AsXmlAsync(DbContextConverterOptions.DEFAULT.WithAll());
                dynamic obj = fromFile.XmlToDynamic();

                ((string)obj.AUTHOR[0].AUT_FIRSTNAME).ShouldBe("John");
            }
        }
        public async Task TestWithXmlFIles()
        {
            //load a context
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            using (SampleContext ctx = xmlFileCtx.InputContext("test1"))
            {
                string fromFile = await ctx.AsXmlAsync(DbContextConverterOptions.DEFAULT.WithAll());

                dynamic obj = fromFile.XmlToDynamic();

                ((string)obj.AUTHOR[0].AUT_FIRSTNAME).ShouldBe("John");
            }
        }
        public async Task TestWithObjectWithParentAndChild(string testin, Int64 postId, ContextDataEnum contextData)
        {
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());

            using (SampleContext ctx = xmlFileCtx.InputContext(testin, "as-xml-tests"))
            {
                ctx.Posts.Find(postId);
                String xml_result_exepcted = GetOutFileContent(testin + contextData.ToString("G") + postId, "as-xml-tests");
                string xml_result_actual = await ctx.AsXmlAsync(contextData);

                var result = await xmlFileCtx.Compare(xml_result_actual, xml_result_exepcted);
                result.AreEqual.ShouldBe(true, result.ToString());
            }
        }
        public async Task TestWithObjectWithParentAndChild(string testin, Int64 postId, ContextDataEnum contextData)
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            using (SampleContext ctx = xmlFileCtx.InputContext(testin, "as-xml-tests"))
            {
                ctx.Posts.Find(postId);
                String xml_result_exepcted = GetOutFileContent(testin + contextData.ToString("G") + postId, "as-xml-tests");
                string xml_result_actual   = await ctx.AsXmlAsync(contextData);

                var result = await xmlFileCtx.Compare(xml_result_actual, xml_result_exepcted);

                result.AreEqual.ShouldBe(true, result.ToString());
            }
        }
Exemplo n.º 11
0
        public async Task ShouldReturnFalseForContextWithSameCollectionCountButDifferentIds()
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test3");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test3");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
            result.Differences.Count.ShouldBe(1);
            result.Differences[0].ToString().ShouldBe("Author was null - object with AUT_ID : 2 (we couldn't find an actual object with expected id  : 2 - this can be caused because the id is auto generated. You could adapt the ids of the expected object)");
        }
        public async Task ShouldReturnFalseForContextWithSameCollectionCountButDifferentIds()
        {
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());

            XmlFileContext<SampleContext> xmlFileExpectedCtx = new XmlFileContext<SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test3");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test3");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
            result.Differences.Count.ShouldBe(1);
            result.Differences[0].ToString().ShouldBe("Author was null - object with AUT_ID : 2 (we couldn't find an actual object with expected id  : 2 - this can be caused because the id is auto generated. You could adapt the ids of the expected object)");

        }
        public async Task TestLoadingChilds(string testin, Int64 autId, ContextDataEnum contextData)
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            string testOut = testin + contextData.ToString("G") + autId;

            using (SampleContext ctx = xmlFileCtx.InputContext(testin, "as-xml-tests"))
            {
                ctx.Authors.Find(autId);

                String xml_result_exepcted = GetOutFileContent(testOut, "as-xml-tests");
                string xml_result_actual   = await ctx.AsXmlAsync(contextData);

                var result = await xmlFileCtx.Compare(xml_result_actual, xml_result_exepcted);

                result.AreEqual.ShouldBe(true, result.ToString());
            }
        }
        public async Task ShouldBeFalseWhenEntityStateAreDifferent()
        {
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());
            XmlFileContext<SampleContext> xmlFileExpectedCtx = new XmlFileContext<SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test4");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test4");
            SampleContext ctx3 = xmlFileExpectedCtx.ExpectedContext("test4b");

            var auth = ctx1.Authors.Find((Int64)1);
            auth.FirstName = "cedric";
            
            var result = await ctx1.CompareTo(ctx2);
            result.AreEqual.ShouldBe(false, result.ToString());

            ctx1.SaveChanges();
            result = await ctx1.CompareTo(ctx3);
            result.AreEqual.ShouldBe(true, result.ToString());

        }
Exemplo n.º 15
0
        public async Task ShouldBeFalseWhenEntityStateAreDifferent()
        {
            XmlFileContext <SampleContext> xmlFileCtx         = new XmlFileContext <SampleContext>(this.GetType());
            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test4");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test4");
            SampleContext ctx3 = xmlFileExpectedCtx.ExpectedContext("test4b");

            var auth = ctx1.Authors.Find((Int64)1);

            auth.FirstName = "cedric";

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false, result.ToString());

            ctx1.SaveChanges();
            result = await ctx1.CompareTo(ctx3);

            result.AreEqual.ShouldBe(true, result.ToString());
        }
        public async Task ShouldRecordOriginalValues(string test)
        {
            var contextFactory = new XmlFileContext <SampleContext>(this.GetType());

            using (SampleContext sampleContext = contextFactory.InputContext(test, "original-values-tests", false).StartRecordingOriginalValues())
            {
                Post post = sampleContext.Posts.Find((Int64)1);
                post.Body = "Changed : " + post.Body;
                sampleContext.SaveChanges();

                var recordedContext = sampleContext.GetRecordedContext();

                sampleContext.PauseRecordingOriginalValues();

                var result = await sampleContext.CompareTo(recordedContext);

                result.AreEqual.ShouldBe(false);
                result.Differences.Count.ShouldBe(1);
                result.Differences[0].ToString().ShouldBe("Post.Body Should be [Original Body] but was [Changed : Original Body] - object with Post_Id : 1");

                sampleContext.StopRecordingOriginalValues();
            }
        }
        public async Task ShouldRecordOriginalValues(string test)
        {
            var contextFactory = new XmlFileContext<SampleContext>(this.GetType());

            using (SampleContext sampleContext = contextFactory.InputContext(test, "original-values-tests", false).StartRecordingOriginalValues())
            {
                Post post = sampleContext.Posts.Find((Int64)1);
                post.Body = "Changed : " + post.Body;
                sampleContext.SaveChanges();

                var recordedContext = sampleContext.GetRecordedContext();

                sampleContext.PauseRecordingOriginalValues();

                var result = await sampleContext.CompareTo(recordedContext);

                result.AreEqual.ShouldBe(false);
                result.Differences.Count.ShouldBe(1);
                result.Differences[0].ToString().ShouldBe("Post.Body Should be [Original Body] but was [Changed : Original Body] - object with Post_Id : 1");

                sampleContext.StopRecordingOriginalValues();

            }
        }
        private SampleContext GetInputContext(string testname)
        {
            XmlFileContext<SampleContext> factory = new XmlFileContext<SampleContext>(this.GetType());

            SampleContext ctx = factory.InputContext(testname, "persistent_tests_input", false);

            return ctx;
        }
        public async Task TestLoadingChilds(string testin, Int64 autId, ContextDataEnum contextData)
        {
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());

            string testOut = testin + contextData.ToString("G") + autId;

            using (SampleContext ctx = xmlFileCtx.InputContext(testin, "as-xml-tests"))
            {
                ctx.Authors.Find(autId);
               
                String xml_result_exepcted = GetOutFileContent(testOut,"as-xml-tests");
                string xml_result_actual = await ctx.AsXmlAsync(contextData);

                var result = await xmlFileCtx.Compare(xml_result_actual, xml_result_exepcted);
                result.AreEqual.ShouldBe(true, result.ToString());
            }
        }
        public async Task ShouldReturnFalseForContextWithEntryContainingDifferentValues()
        {
            XmlFileContext<SampleContext> xmlFileCtx = new XmlFileContext<SampleContext>(this.GetType());
            XmlFileContext<SampleContext> xmlFileExpectedCtx = new XmlFileContext<SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test2");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test2");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
            result.Differences.Count.ShouldBe(2);

            result.Differences[0].ObjectId.ShouldBe("2");
            result.Differences[0].ObjectName.ShouldBe("Post");
            result.Differences[0].PropertyName.ShouldBe("Subject");
            result.Differences[0].ActualPropertyContent.ShouldBe("First Text");
            result.Differences[0].ExpectedPropertyContent.ShouldBe("First Text Modified");
            result.Differences[0].ToString().ShouldBe("Post.Subject Should be [First Text Modified] but was [First Text] - object with Post_Id : 2");

            result.Differences[1].ObjectId.ShouldBe("2");
            result.Differences[1].ObjectName.ShouldBe("Post");
            result.Differences[1].PropertyName.ShouldBe("Body");
            result.Differences[1].ActualPropertyContent.ShouldBe("Some Text here");
            result.Differences[1].ExpectedPropertyContent.ShouldBe("Some Other Text here");
        }