public async Task Xml_Data_Saved_In_DataBase_Should_Be_Properly_Restored()
        {
            ServiceCollection services =
                new ServiceCollectionBuilder().PrepareServiceCollection(s =>
            {
                s.ResetDapperCustomTypeHandlers();
                s.RegisterDapperCustomTypeHandlers(Assembly.GetExecutingAssembly());
            });

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;

                ITestObjectRepository testObjectRepository = scopedServices.GetRequiredService <ITestObjectRepository>();

                TestXmlObject testObject = CreateFullTestObject();

                // Act
                await testObjectRepository.SaveTestXmlObject(testObject);

                TestXmlObject retrievedTestObject = await testObjectRepository.GetTestXmlObject(testObject.Id);

                // Assert
                retrievedTestObject.Should().NotBeNull();
                retrievedTestObject.Should().BeEquivalentTo(testObject);
                retrievedTestObject.Content.Should().BeEquivalentTo(testObject.Content);
            }
        }
Esempio n. 2
0
        public virtual void CyclicTestXmlObject()
        {
            TestXmlObject[] array = new TestXmlObject[3];
            array[0] = new TestXmlObject();
            array[1] = new TestXmlObject();
            array[2] = array[0];
            FillTestXmlObject(array[0], 23);
            FillTestXmlObject(array[1], 46);

            TestXmlObject[] result = CheckCyclic <TestXmlObject[]>(array);
            Assert.AssertSame(result[2], result[0]);
            Assert.AssertNull(result[0].TransientField1);
            Assert.AssertNull(result[0].TransientField2);
            Assert.AssertNull(result[1].TransientField1);
            Assert.AssertNull(result[2].TransientField2);
        }
Esempio n. 3
0
 protected void FillTestXmlObject(TestXmlObject obj, int baseNumber)
 {
     obj.TransientField1 = new Object();
     obj.TransientField2 = new Object();
     obj.ValueBoolean    = true;
     obj.ValueBooleanN   = obj.ValueBoolean;
     obj.ValueByte       = (byte)(55 + baseNumber);
     obj.ValueByteN      = obj.ValueByte;
     obj.ValueCharacter  = (char)(66 + baseNumber);
     obj.ValueCharacterN = obj.ValueCharacter;
     obj.ValueDouble     = (77 + baseNumber);
     obj.ValueDoubleN    = obj.ValueDouble;
     obj.ValueFloat      = (88 + baseNumber);
     obj.ValueFloatN     = obj.ValueFloat;
     obj.ValueInteger    = (99 + baseNumber);
     obj.ValueIntegerN   = obj.ValueInteger;
     obj.ValueLong       = (111 + baseNumber);
     obj.ValueLongN      = obj.ValueLong;
     obj.ValueString     = "133_" + baseNumber;
 }
Esempio n. 4
0
        public void When_Custom_Xml_Handler_Is_Not_Registered_Exception_Should_Be_Thrown()
        {
            ServiceCollection services =
                new ServiceCollectionBuilder().PrepareServiceCollection(s =>
            {
                s.ResetDapperCustomTypeHandlers();
            });

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;

                ITestObjectRepository testObjectRepository = scopedServices.GetRequiredService <ITestObjectRepository>();

                TestXmlObject testObject = CreateTestXmlObject();

                // Assert
                Assert.ThrowsAsync <NotSupportedException>(async() => await testObjectRepository.SaveTestXmlObject(testObject));
            }
        }
Esempio n. 5
0
        public void When_Custom_Xml_Handler_Is_Registered_Exception_Should_Not_Be_Thrown_V2()
        {
            ServiceCollection services =
                new ServiceCollectionBuilder().PrepareServiceCollection(s =>
            {
                s.ResetDapperCustomTypeHandlers();
                s.RegisterDapperCustomTypeHandlers(new[] { Assembly.GetExecutingAssembly() });
            });

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;

                ITestObjectRepository testObjectRepository = scopedServices.GetRequiredService <ITestObjectRepository>();

                TestXmlObject testObject = CreateTestXmlObject();

                // Assert
                Assert.DoesNotThrowAsync(async() => await testObjectRepository.SaveTestXmlObject(testObject));
            }
        }
        public async Task Null_Xml_Data_Saved_In_DataBase_Should_Be_Restored_As_Null_Object()
        {
            ServiceCollection services =
                new ServiceCollectionBuilder().PrepareServiceCollection(s =>
            {
                s.ResetDapperCustomTypeHandlers();
                s.RegisterDapperCustomTypeHandlers(Assembly.GetExecutingAssembly());
            });

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            using (IServiceScope scope = serviceProvider.CreateScope())
            {
                var scopedServices = scope.ServiceProvider;

                ITestObjectRepository testObjectRepository = scopedServices.GetRequiredService <ITestObjectRepository>();

                TestXmlObject testObject = new TestXmlObject
                {
                    FirstName = "John",
                    LastName  = "Doe",
                    StartWork = new DateTime(2018, 06, 01),
                    Content   = null
                };

                // Act
                await testObjectRepository.SaveTestXmlObject(testObject);

                TestXmlObject retrievedTestObject = await testObjectRepository.GetTestXmlObject(testObject.Id);

                // Assert
                retrievedTestObject.Should().NotBeNull();
                retrievedTestObject.Should().BeEquivalentTo(testObject);
                retrievedTestObject.Content.Should().BeEquivalentTo(testObject.Content);
            }
        }