/// <summary>
 /// - Create a test class, set ADecimalValue to '@from' and save it to RavenDB
 /// - Load the instance in a new session, change the value to 'to' and save changes
 /// - Load the instance in a new session and verify that in the previous stap ADecimalValue was actually changed
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 private void ChangeADecimalValue(decimal @from, decimal to)
 {
     using (var store = NewDocumentStore())
     {
         string id;
         using (var ses = store.OpenSession())
         {
             var ding = new TestClass { ADecimalValue = @from };
             ses.Store(ding);
             ses.SaveChanges();
             id = ding.Id;
         }
         using (var ses = store.OpenSession())
         {
             var ding = ses.Load<TestClass>(id);
             ding.ADecimalValue = to;
             ses.SaveChanges();
         }
         using (var ses = store.OpenSession())
         {
             var ding = ses.Load<TestClass>(id);
             Assert.Equal(to, ding.ADecimalValue);
         }
     }
 }
 public void CanWriteWriteOnlyPropertyByOrdinal()
 {
     var x = new TestClass() {MyInt = 4};
     var ordinal = SetterDelegateCache<TestClass>.OrdinalLookup["MyWriteOnlyInt"];
     SetterDelegateCache<TestClass>.Write(ordinal, x, 5);
     x.MyInt.ShouldEqual(5);
 }
 public void CanWriteByOrdinal()
 {
     var x = new TestClass() {MyInt = 3};
     var ordinal = SetterDelegateCache<TestClass>.OrdinalLookup["MyInt"];
     SetterDelegateCache<TestClass>.Write(ordinal, x, 4);
     x.MyInt.ShouldEqual(4);
 }
Пример #4
0
 public void PosTest2()
 {
     TestClass tc = new TestClass();
     Type tpA = tc.GetType();
     EventInfo eventinfo = tpA.GetEvent("Event1");
     MethodInfo methodinfo = eventinfo.GetRaiseMethod(false);
     Assert.Null(methodinfo);
 }
Пример #5
0
            public void GetterReturnsProperty()
            {
                var type = EntityTypes.Register<TestClass>();
                var idProperty = type.GetProperty<TestClass>(t => t.Id);
                var test = new TestClass { Id = 1 };

                Assert.Equal(idProperty.Getter(test), 1);
            }
Пример #6
0
 public void PosTest6()
 {
     TestClass tc = new TestClass();
     Type tpA = tc.GetType();
     EventInfo eventinfo = tpA.GetEvent("Event3", BindingFlags.NonPublic | BindingFlags.Instance);
     MethodInfo methodinfo = eventinfo.GetRaiseMethod(false);
     Assert.Null(methodinfo);
 }
        public static void DangerousGetPinnableReferencePointerDangerousCreate1()
        {
            TestClass testClass = new TestClass();
            Span<char> span = Span<char>.DangerousCreate(testClass, ref testClass.C1, 3);

            ref char pinnableReference = ref span.DangerousGetPinnableReference();
            Assert.True(Unsafe.AreSame<char>(ref testClass.C1, ref pinnableReference));
        }
        public void CanReadProperty()
        {
            var pi = typeof (TestClass).GetProperty("Value");
            var getter = pi.BuildGetDelegate<TestClass>();

            var x = new TestClass() {Value = 2};
            getter(x).ShouldEqual(2);
        }
Пример #9
0
 public static void DangerousCreateBadLength()
 {
     Assert.Throws<ArgumentOutOfRangeException>(
         delegate ()
         {
             TestClass testClass = new TestClass();
             ReadOnlySpan<char> span = ReadOnlySpan<char>.DangerousCreate(testClass, ref testClass.C1, -1);
         });
 }
        public void CanWriteProperty()
        {
            var pi = typeof(TestClass).GetProperty("Value");
            var setter = pi.BuildSetDelegate<TestClass>();

            var x = new TestClass() {Value = 2};
            setter(x, 3);
            x.Value.ShouldEqual(3);
        }
        public void CompositeRendererCallsFuncToRender()
        {
            var compositeRenderer = new CompositeRenderer<TestClass>(p => p.Firstname + " " + p.Nickname + " " + p.Age);
            var testClass = new TestClass() {Firstname = "Daniel", Nickname = "Tigraine", Age = 24};
            
            string render = compositeRenderer.Render(testClass);

            Assert.Equal("Daniel Tigraine 24", render);
        }
Пример #12
0
            public void SetterSetsProperty()
            {
                var type = EntityTypes.Register<TestClass>();
                var idProperty = type.GetProperty<TestClass>(t => t.Id);
                var test = new TestClass();

                idProperty.Setter(test, 1);

                Assert.Equal(test.Id, 1);
            }
        public void TestNull()
        {
            var obj = new TestClass { Addresses = null };
            var json = obj.ToJson();
            var expected = "{ 'Addresses' : null }".Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
Пример #14
0
            public void ComparerComparesProperty()
            {
                var type = EntityTypes.Register<TestClass>();
                var idProperty = type.GetProperty<TestClass>(t => t.Id);
                var a = new TestClass() { Id = 1 };
                var b = new TestClass() { Id = 1 };

                Assert.True(idProperty.Comparer(a, b));

                b.Id = 2;

                Assert.False(idProperty.Comparer(a, b));
            }
Пример #15
0
        public static void DangerousCreate1()
        {
            TestClass testClass = new TestClass();
            testClass.C0 = 'a';
            testClass.C1 = 'b';
            testClass.C2 = 'c';
            testClass.C3 = 'd';
            testClass.C4 = 'e';
            ReadOnlySpan<char> span = ReadOnlySpan<char>.DangerousCreate(testClass, ref testClass.C1, 3);
            span.Validate<char>('b', 'c', 'd');

            ref char pc1 = ref span.DangerousGetPinnableReference();
            Assert.True(Unsafe.AreSame<char>(ref testClass.C1, ref pc1));
        }
Пример #16
0
        public void Should_Get_Value()
        {
            var testObject = new TestClass {Value = 12};
            _config["IntValue"] = 12;
            _config["StringValue"] = "Test string";
            _config["ObjectValue"] = testObject;

            _config["IntValue"].ShouldBe(12);
            _config.Get<int>("IntValue").ShouldBe(12);

            _config["StringValue"].ShouldBe("Test string");
            _config.Get<string>("StringValue").ShouldBe("Test string");

            _config["ObjectValue"].ShouldBeSameAs(testObject);
            _config.Get<TestClass>("ObjectValue").ShouldBeSameAs(testObject);
            _config.Get<TestClass>("ObjectValue").Value.ShouldBe(12);
        }
        public void TestSerialization()
        {
            var obj = new TestClass
            {
                Addresses = new HashSet<Address>
                {
                    new Address { Street = "123 Main", City = "Smithtown", State = "PA", Zip = 12345 },
                    new Address { Street = "456 First", City = "Johnstown", State = "MD", Zip = 45678 }
                }
            };
            var json = obj.ToJson();
            var expected = "{ 'Addresses' : [#A1, #A2] }";
            expected = expected.Replace("#A1", "{ 'Street' : '123 Main', 'City' : 'Smithtown', 'State' : 'PA', 'Zip' : 12345 }");
            expected = expected.Replace("#A2", "{ 'Street' : '456 First', 'City' : 'Johnstown', 'State' : 'MD', 'Zip' : 45678 }");
            expected = expected.Replace("'", "\"");
            Assert.Equal(expected, json);

            var bson = obj.ToBson();
            var rehydrated = BsonSerializer.Deserialize<TestClass>(bson);
            Assert.IsType<HashSet<Address>>(rehydrated.Addresses);
            Assert.True(bson.SequenceEqual(rehydrated.ToBson()));
        }
        public void Should_be_able_to_save_and_load_DomainReference()
        {
            var id = "";

            using (var session = sessionProvider.GetSession())
            {
                var testClass = new TestClass
                    {
                        UserReference = DomainReference<User>.Create("Kalle", "Kula"),
                    };

                session.Store(testClass);
                session.SaveChanges();
                id = testClass.Id;
            }

            using (var session = sessionProvider.GetSession())
            {
                var testClass = session.Load<TestClass>(id);

                Assert.Equal("Kalle", testClass.UserReference.Id);
                Assert.Equal("Kula", testClass.UserReference.Name);
            }
        }
Пример #19
0
        static TestClass SetupTestClass()
        {
            var testClass = new TestClass { Integer = 3, String = "testString", Boolean = true, nestedClass =  new TestClass.NestedClass(TestClass.NestedEnum.Nested_NotQuite) };

            return testClass;
        }
 public void CanWriteWriteOnlyProperty()
 {
     var x = new TestClass() {MyInt = 2};
     SetterDelegateCache<TestClass>.Write("MyWriteOnlyInt", x, 3);
     x.MyInt.ShouldEqual(3);
 }
 public void CanWritePublicProperty()
 {
     var x = new TestClass() {MyInt = 1};
     SetterDelegateCache<TestClass>.Write("MyInt", x, 2);
     x.MyInt.ShouldEqual(2);
 }
 public void CanReadPublicProperty()
 {
     var x = new TestClass() {MyInt = 1};
     GetterDelegateCache<TestClass>.Read("MyInt", x).ShouldEqual(1);
 }
 public void CanReadReadOnlyPropertyByOrdinal()
 {
     var x = new TestClass() { MyInt = 4 };
     var ordinal = GetterDelegateCache<TestClass>.OrdinalLookup["MyReadOnlyInt"];
     GetterDelegateCache<TestClass>.Read(ordinal, x).ShouldEqual(4);
 }
        public void ReadAsAsync_WhenContentIsObjectContentAndValueIsCompatibleType_ReadsValueFromObjectContent()
        {
            _formatterMock.Setup(f => f.CanWriteType(typeof(TestClass))).Returns(true);
            var value = new TestClass();
            var content = new ObjectContent<TestClass>(value, _formatterMock.Object);

            Assert.Same(value, content.ReadAsAsync<object>(_formatters).Result);
            Assert.Same(value, content.ReadAsAsync<TestClass>(_formatters).Result);
            Assert.Same(value, content.ReadAsAsync(typeof(object), _formatters).Result);
            Assert.Same(value, content.ReadAsAsync(typeof(TestClass), _formatters).Result);

            _formatterMock.Verify(f => f.ReadFromStreamAsync(It.IsAny<Type>(), It.IsAny<Stream>(), content.Headers, It.IsAny<IFormatterLogger>()), Times.Never());
        }
Пример #25
0
 public void OnEntryIsCalled()
 {
     var t = new TestClass();
     t.SimpleMethod();
     Assert.True (callsBag.Contains ("AssemblyAspect"));
 }
Пример #26
0
 public bool ClassFailed(Xunit.TestClass testClass, string exceptionType, string message, string stackTrace)
 {
     return(false);
 }
 public void ConvertFrom()
 {
     IDictionary<string, object> Result = new TestClass() { A = "This is a test", B = 10 }.To<TestClass, ExpandoObject>();
     Assert.Equal(10, Result["B"]);
     Assert.Equal("This is a test", Result["A"]);
 }
 public void VarianceTest()
 {
     Assert.InRange(new double[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().Variance(), 7.5, 7.6);
     Assert.InRange(new float[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().Variance(), 7.5, 7.6);
     Assert.InRange(new int[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().Variance(), 7.5, 7.6);
     Assert.InRange(new decimal[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().Variance(), 7.5, 7.6);
     Assert.InRange(new long[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().Variance(), 7.5, 7.6);
     var Values = new TestClass[]
     {
         new TestClass{DoubleValue=5,FloatValue=5,IntValue=5,DecimalValue=5,LongValue=5},
         new TestClass{DoubleValue=4,FloatValue=4,IntValue=4,DecimalValue=4,LongValue=4},
         new TestClass{DoubleValue=2,FloatValue=2,IntValue=2,DecimalValue=2,LongValue=2},
         new TestClass{DoubleValue=4,FloatValue=4,IntValue=4,DecimalValue=4,LongValue=4},
         new TestClass{DoubleValue=7,FloatValue=7,IntValue=7,DecimalValue=7,LongValue=7},
         new TestClass{DoubleValue=9,FloatValue=9,IntValue=9,DecimalValue=9,LongValue=9},
         new TestClass{DoubleValue=1,FloatValue=1,IntValue=1,DecimalValue=1,LongValue=1},
         new TestClass{DoubleValue=2,FloatValue=2,IntValue=2,DecimalValue=2,LongValue=2},
         new TestClass{DoubleValue=0,FloatValue=0,IntValue=0,DecimalValue=0,LongValue=0}
     };
     Assert.InRange(Values.Variance(x => x.DoubleValue), 7.5, 7.6);
     Assert.InRange(Values.Variance(x => x.FloatValue), 7.5, 7.6);
     Assert.InRange(Values.Variance(x => x.IntValue), 7.5, 7.6);
     Assert.InRange(Values.Variance(x => x.DecimalValue), 7.5, 7.6);
     Assert.InRange(Values.Variance(x => x.LongValue), 7.5, 7.6);
 }
 public void StandardDeviationTest()
 {
     Assert.InRange(new double[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().StandardDeviation(), 2.73, 2.74);
     Assert.InRange(new float[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().StandardDeviation(), 2.73, 2.74);
     Assert.InRange(new int[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().StandardDeviation(), 2.73, 2.74);
     Assert.InRange(new decimal[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().StandardDeviation(), 2.73, 2.74);
     Assert.InRange(new long[] { 5, 4, 2, 4, 7, 9, 1, 2, 0 }.ToList().StandardDeviation(), 2.73, 2.74);
     var Values = new TestClass[]
     {
         new TestClass{DoubleValue=5,FloatValue=5,IntValue=5,DecimalValue=5,LongValue=5},
         new TestClass{DoubleValue=4,FloatValue=4,IntValue=4,DecimalValue=4,LongValue=4},
         new TestClass{DoubleValue=2,FloatValue=2,IntValue=2,DecimalValue=2,LongValue=2},
         new TestClass{DoubleValue=4,FloatValue=4,IntValue=4,DecimalValue=4,LongValue=4},
         new TestClass{DoubleValue=7,FloatValue=7,IntValue=7,DecimalValue=7,LongValue=7},
         new TestClass{DoubleValue=9,FloatValue=9,IntValue=9,DecimalValue=9,LongValue=9},
         new TestClass{DoubleValue=1,FloatValue=1,IntValue=1,DecimalValue=1,LongValue=1},
         new TestClass{DoubleValue=2,FloatValue=2,IntValue=2,DecimalValue=2,LongValue=2},
         new TestClass{DoubleValue=0,FloatValue=0,IntValue=0,DecimalValue=0,LongValue=0}
     };
     Assert.InRange(Values.StandardDeviation(x => x.DoubleValue), 2.73, 2.74);
     Assert.InRange(Values.StandardDeviation(x => x.FloatValue), 2.73, 2.74);
     Assert.InRange(Values.StandardDeviation(x => x.IntValue), 2.73, 2.74);
     Assert.InRange(Values.StandardDeviation(x => x.DecimalValue), 2.73, 2.74);
     Assert.InRange(Values.StandardDeviation(x => x.LongValue), 2.73, 2.74);
 }
        public void ReadAsAsync_WhenContentIsObjectContentAndValueIsNotCompatibleType_SerializesAndDeserializesValue()
        {
            _formatterMock.Setup(f => f.CanWriteType(typeof(TestClass))).Returns(true);
            _formatterMock.Setup(f => f.CanReadType(typeof(string))).Returns(true);
            var value = new TestClass();
            var content = new ObjectContent<TestClass>(value, _formatterMock.Object, _mediaType.MediaType);
            SetupUpRoundTripSerialization(type => new TestClass());

            Assert.Throws<InvalidCastException>(() => content.ReadAsAsync<string>(_formatters).RethrowFaultedTaskException());

            Assert.IsNotType<string>(content.ReadAsAsync(typeof(string), _formatters).Result);

            _formatterMock.Verify(f => f.ReadFromStreamAsync(It.IsAny<Type>(), It.IsAny<Stream>(), content.Headers, It.IsAny<IFormatterLogger>()), Times.Exactly(2));
        }
 public void CanReadReadOnlyProperty()
 {
     var x = new TestClass() {MyInt = 2};
     GetterDelegateCache<TestClass>.Read("MyReadOnlyInt", x).ShouldEqual(2);
 }