コード例 #1
0
        public async Task ShouldCompareTwoContextWithSimpleContent()
        {
            using (SampleContext expectedContext = GetSimpleTestContext())
            {
                using (SampleContext appContext = new XmlFileContext <SampleContext>(this.GetType()).Empty())
                {
                    appContext.Authors.Add(new Author()
                    {
                        FirstName = "Cedric123"
                    });
                    appContext.SaveChanges();

                    //compare context
                    var comparisonResult = await appContext.CompareTo(expectedContext);

                    string s = await appContext.AsXmlAsync();

                    string s2 = await expectedContext.AsXmlAsync(ContextDataEnum.All);

                    comparisonResult.AreEqual.ShouldBe(false, comparisonResult.ToString());
                    comparisonResult.Differences.Count.ShouldBe(2);
                    comparisonResult.Differences[0].ToString()
                    .ShouldBe("Author.FirstName Should be [Cedric] but was [Cedric123] - object with AUT_ID : 1");
                }
            }
        }
コード例 #2
0
        public async Task OriginalShouldBeSameAsInput(string fileName, ContextDataEnum contextData, decimal autId)
        {
            string filepath = this.GetType().AssemblyDirectory() + "\\input\\" + fileName;

            string xml_result_ori        = null;
            string xml_result_actual     = null;
            XmlComparisonResult result   = null;
            XmlComparisonUtils  xmlUtils = new XmlComparisonUtils();

            using (SampleContext sampleContext = DbContextFactory <SampleContext> .Create(filepath, ConnectionBehaviour.Persistent, connectionName))
            {
                sampleContext.StartRecordingOriginalValues();

                //just load the author
                var autor = sampleContext.Authors.FirstOrDefault(aut => aut.Id == autId);
                autor.ShouldNotBe(null, $"author with id {autId} test {fileName}");

                xml_result_actual = await sampleContext.AsXmlAsync(contextData);

                xml_result_ori = await sampleContext.GetRecordedContext().AsXmlAsync(contextData);

                result = xmlUtils.CompareXml(xml_result_actual, xml_result_ori);
                result.AreEqual.ShouldBe(true, result.ToString());

                sampleContext.StopRecordingOriginalValues();
            }
        }
コード例 #3
0
        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");
            }
        }
コード例 #4
0
        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());
            }
        }
コード例 #5
0
        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());
            }
        }
コード例 #6
0
        public async Task TestReturnEmptyXml()
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            using (SampleContext emptyContext = xmlFileCtx.Empty())
            {
                Author aut1 = new Author();
                aut1.FirstName = "testname";

                emptyContext.Authors.Attach(aut1);

                string fromFile = await emptyContext.AsXmlAsync(DbContextConverterOptions.DEFAULT.WithNullValues());

                dynamic obj = fromFile.XmlToDynamic();

                ((string)obj.AUTHOR[0].AUT_FIRSTNAME).ShouldBe("testname");
            }
        }