public void BindOther()
        {
            var foo = new Foo("123");
            var bar = new Bar(foo);

            AssertChange(foo, bar, x => x.FooDependentValue, () => foo.Value = "arbitrary");
        }
示例#2
0
        public void FooTest()
        {
            var sqlConnectionFoo = new Foo<SqlConnection>();
            var oleDbConnectionFoo = new Foo<OleDbConnection>(new OleDbConnection());

            IDbConnection connection = new SqlConnection();
        }
示例#3
0
        public void AreSetEventEnabled_disables_events()
        {
            // arrange
            var prevField1 = default(string);
            var prevField2 = default(DateTime);
            var field1 = "test";
            var field2 = DateTime.UtcNow;
            storage[0] = new Dictionary<string, object>{
                {"Field1", prevField1},
                {"Field2", prevField2}
            };
            var foo = new Foo(0, dBCollectionMock.Object);

            // act
            foo.AreSetEventsEnabled = false;
            foo.Field1 = field1;
            foo.Field2 = field2;
            foo.Commit();

            // assert
            storage[0]["Field1"].Should().Be(prevField1);
            storage[0]["Field2"].Should().Be(prevField2);
            foo.Field1.Should().Be(field1);
            foo.Field2.Should().Be(field2);
        }
示例#4
0
 public void ProperContentType()
 {
     var content = new Foo();
     var message = new FakeConsumedMessage(content, FakeBasicDeliverEventArgs());
     var actual = message.As<Foo>();
     Assert.Equal(content, actual.Content);
 }
示例#5
0
        public void TestPushPop()
        {
            var p0 = new Pool<Foo>();
            var p1 = new Pool<Foo>(1);

            var f = new Foo();
            var g = new Foo();

            p0.Push(f);
            Assert.AreEqual(1, p0.Count);
            p0.Push(g);
            Assert.AreEqual(2, p0.Count);

            p1.Push(f);
            Assert.AreEqual(1, p1.Count);
            // capacity overflow
            p1.Push(g);
            Assert.AreEqual(1, p1.Count);

            Foo g1 = p0.Pop();
            Assert.AreSame(g, g1);
            Foo f1 = p0.Pop();
            Assert.AreSame(f, f1);

            Foo f2 = p1.Pop();
            Assert.AreSame(f, f2);
            // pop underflow
            Foo g2 = p1.Pop();
            Assert.AreSame(null, g2);
        }
示例#6
0
        public void EqualsShouldBeTheSameAsEq()
        {
            // Create two equal but distinct strings
            string a = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
            string b = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });

            Assert.IsTrue(a == b);
            Assert.IsTrue(a.Equals(b));

            object c = a;
            object d = b;

            Assert.IsFalse(c == d);
            Assert.IsTrue(c.Equals(d));

            if(new Foo())
            {

            }
            else
            {
                Assert.Fail("should fail");
            }

            Foo foo = new Foo();
        }
            public void ShouldSerializeWithCircularReferences()
            {
                var foo = new Foo();
                foo.Parent = foo;

                Assert.DoesNotThrow(() => _serializer.Serialize(foo));
            }
 public void ArrayToDelimitedString()
 {
     Foo[] arr = new Foo[] {new Foo("Foo"), new Foo("Bar")};
     Assert.AreEqual(
         ":Foo,:Bar", StringUtils.CollectionToCommaDelimitedString(arr));
     Assert.AreEqual("null", StringUtils.CollectionToCommaDelimitedString<object>(null));
 }
        public void ShouldReturnDefaultIfNoneStored()
        {
            var foo = new Foo();
            var value = NotifiableProperty.Get(foo, x => x.Age);

            Assert.AreEqual(0, value);
        }
        public void TestSave()
        {
            var server = Configuration.TestServer;
            var database = Configuration.TestDatabase;
            var collection = Configuration.GetTestCollection<Foo>();

            var conventions = new ConventionPack();
            conventions.Add(new NamedIdMemberConvention(new[] { "FooId" }));
            ConventionRegistry.Register("test", conventions, t => t == typeof(Foo));

            var classMap = new BsonClassMap<Foo>(cm => cm.AutoMap());

            collection.RemoveAll();
            for (int i = 0; i < 10; i++)
            {
                var foo = new Foo
                {
                    FooId = ObjectId.Empty,
                    Name = string.Format("Foo-{0}", i),
                    Summary = string.Format("Summary for Foo-{0}", i)
                };
                collection.Save(foo);
                var count = collection.Count();
                Assert.AreEqual(i + 1, count);
            }
        }
        public void SetPropertyValue_Sets_String_Property()
        {
            var foo = new Foo();
            foo.SetPropertyValue("StringProperty", "Hello Mvc!");

            Assert.IsNotNull(foo.StringProperty);
        }
        public void SetPropertyValue_Sets_Nullable_Property()
        {
            var foo = new Foo() { NullableInt32Property = 32 };
            foo.SetPropertyValue("NullableInt32Property", null);

            Assert.IsNull(foo.NullableInt32Property);
        }
        public void SetPropertyValue_Sets_Boolean_Property()
        {
            var foo = new Foo();
            foo.SetPropertyValue("BooleanProperty", true);

            Assert.IsTrue(foo.BooleanProperty);
        }
        public void SetPropertyValue_Converts_String_To_Boolean_And_Sets_Value()
        {
            var foo = new Foo();
            foo.SetPropertyValue("BooleanProperty", "true");

            Assert.IsTrue(foo.BooleanProperty);
        }
示例#15
0
        public void HeaderMapping()
        {
            var content = new Foo();
            const String messageId = "one-id";
            const Int64 timestamp = 123456789L;
            const String replyExchangeType = "direct";
            const String replyExchangeName = "exchange-name";
            const String replyRoutingKey = "routing-key";
            const String correlationId = "one-correlation-id";
            var replyTo = $"{replyExchangeType}://{replyExchangeName}/{replyRoutingKey}";

            var args = new BasicDeliverEventArgs
                           {
                               BasicProperties = new BasicProperties
                                                     {
                                                         MessageId = messageId,
                                                         Timestamp = new AmqpTimestamp(timestamp),
                                                         CorrelationId = correlationId,
                                                         ReplyTo = replyTo
                                                     }
                           };
            var message = new FakeConsumedMessage(content, args);
            var actual = message.To<Foo>();
            Assert.Equal(messageId, actual.Headers.MessageId);
            Assert.Equal(timestamp, actual.Headers.Timestamp);
            Assert.Equal(correlationId, actual.Headers.CorrelationId);
            Assert.Equal(replyTo, actual.Headers.ReplyConfiguration.ToString());
        }
示例#16
0
        public void DependencyOrderingWorksWithSubclassesAsWellAsPrimitives()
        {
            var rootObject = new Foo();
            var filler = new Filler();

            var generator = MockRepository.GenerateStub<IGenerateDummyData>();
            generator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything)).Return("Chris");

            var dependentGenerator = MockRepository.GenerateStub<IGenerateDummyData>();
            dependentGenerator.Stub(g => g.Generate(Arg<GenerationContext>.Is.Anything))
                .Do(new GeneratorDelegate(context => string.Format("Hello {0}", context.RootAs<Foo>().Bar.Name)));

            filler.Configure<Goo>(config => config.For(goo => goo.Name).Use(dependentGenerator));
            filler.Configure<Bar>(config => config.For(goo => goo.Name).Use(generator));

            filler.Configure<Foo>(config =>
            {
                config.For(f => f.Goo).Order(2);
                config.For(f => f.Bar).Order(1);
            });

            filler.Fill(rootObject);

            Assert.That(rootObject.Goo.Name, Is.EqualTo("Hello Chris"));
        }
        public void TestSerializeRespected()
        {
            var obj = new Foo { X = "abc", Z = "def" }; // don't touch Y...

            string json = JsonSerializer.SerializeToString(obj);
            Assert.That(json, Is.StringMatching("{\"X\":\"abc\",\"Z\":\"def\"}"));   
        }
        public void If_no_exception_occurred_then_changes_are_saved()
        {
            var testDocument = new Foo { Id = "foos/123", Title = "foo" };

            var store = new TestableStore();

            var controller = new TestableController(store);

            StartActionExecuting(controller);

            using (var session = controller.Session)
            {
                session.Store(testDocument);
                session.SaveChanges();

                var doc = session.Load<Foo>(testDocument.Id);
                doc.Title = "bar";

                FinishActionExecuted(controller);
            }

            using (var session = store.OpenSession())
            {
                var doc = session.Load<Foo>(testDocument.Id);
                Assert.Equal("bar", doc.Title);
            }
        }
		public void Export_And_Import_Retains_HiLoState()
		{
			using (var session = documentStore.OpenSession()) {
				var foo = new Foo() { Something = "something2" };
				Assert.Null(foo.Id);
				session.Store(foo);
				Assert.NotNull(foo.Id);
				session.SaveChanges();
			}

			if (File.Exists("hilo-export.dump"))
				File.Delete("hilo-export.dump");
			Smuggler.Smuggler.ExportData(new Smuggler.Smuggler.ExportSpec("http://localhost:8079/", "hilo-export.dump", false, false));
			Assert.True(File.Exists("hilo-export.dump"));

			using (var session = documentStore.OpenSession()) {
				var hilo = session.Load<HiLoKey>("Raven/Hilo/foos");
				Assert.NotNull(hilo);
				Assert.Equal(32, hilo.Max);
			}

			server.Dispose();
			CreateServer();

			Smuggler.Smuggler.ImportData("http://localhost:8079/", "hilo-export.dump");

			using (var session = documentStore.OpenSession()) {
				var hilo = session.Load<HiLoKey>("Raven/Hilo/foos");
				Assert.NotNull(hilo);
				Assert.Equal(32, hilo.Max);
			}
		}
			public void WhenSavingSettings_ThenCanReadThem()
			{
                var manager = new SettingsManager(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider);

				var foo = new Foo
				{
					StringProperty = "World",
					IntProperty = -1,
					DefaultValueIntProperty = -20,
					DefaultValueAsStringIntProperty = 25,
					EnumProperty = UriFormat.SafeUnescaped,
					DefaultValueEnumProperty = UriFormat.Unescaped,
					ComplexTypeWithConverter = new Bar("BarValue"),
					PingInterval = TimeSpan.FromMinutes(2),
				};

				manager.Save(foo);

				var saved = new Foo();
				manager.Read(saved);

				Assert.Equal("World", saved.StringProperty);
				Assert.Equal("Hello", saved.DefaultValueStringProperty);
				Assert.Equal(-1, saved.IntProperty);
				Assert.Equal(-20, saved.DefaultValueIntProperty);
				Assert.Equal(25, saved.DefaultValueAsStringIntProperty);
				Assert.Equal(UriFormat.SafeUnescaped, saved.EnumProperty);
				Assert.Equal(UriFormat.Unescaped, saved.DefaultValueEnumProperty);
				Assert.NotNull(saved.ComplexTypeWithConverter);
				Assert.Equal("BarValue", saved.ComplexTypeWithConverter.Value);
				Assert.Equal(TimeSpan.FromMinutes(2), saved.PingInterval);
			}
        public void TestSave()
        {
            collection.RemoveAll();
            var foo1 = new Foo
            {
                Id = new Id { AccountId = 1, Index = 2 },
                Name = "foo1"
            };
            collection.Save(foo1);

            var foo1Rehydrated = collection.FindOne(Query.EQ("_id", BsonDocumentWrapper.Create(foo1.Id)));
            Assert.IsInstanceOf<Foo>(foo1Rehydrated);
            Assert.IsInstanceOf<Id>(foo1Rehydrated.Id);
            Assert.AreEqual(1, foo1Rehydrated.Id.AccountId);
            Assert.AreEqual(2, foo1Rehydrated.Id.Index);
            Assert.AreEqual("foo1", foo1Rehydrated.Name);

            var foo2 = new Foo
            {
                Id = new IdWithExtraField { AccountId = 3, Index = 4, Extra = 5 },
                Name = "foo2"
            };
            collection.Save(foo2);

            var foo2Rehydrated = collection.FindOne(Query.EQ("_id", BsonDocumentWrapper.Create(foo2.Id)));
            Assert.IsInstanceOf<Foo>(foo2Rehydrated);
            Assert.IsInstanceOf<IdWithExtraField>(foo2Rehydrated.Id);
            Assert.AreEqual(3, foo2Rehydrated.Id.AccountId);
            Assert.AreEqual(4, foo2Rehydrated.Id.Index);
            Assert.AreEqual(5, ((IdWithExtraField)foo2Rehydrated.Id).Extra);
            Assert.AreEqual("foo2", foo2Rehydrated.Name);
        }
示例#22
0
		public void Can_Save_And_Load_DateTimeOffset_From_Metadata()
		{
			using (var documentStore = NewDocumentStore())
			{
				var dto = new DateTimeOffset(2012, 1, 1, 8, 0, 0, TimeSpan.FromHours(-2));
				using (var session = documentStore.OpenSession())
				{
					var foo = new Foo { Id = "foos/1" };
					session.Store(foo);
					var metadata = session.Advanced.GetMetadataFor(foo);
					metadata.Add("TestDTO", dto); 
					session.SaveChanges();
				}

				WaitForUserToContinueTheTest(documentStore);

				using (var session = documentStore.OpenSession())
				{
					var foo = session.Load<Foo>("foos/1");
					var metadata = session.Advanced.GetMetadataFor(foo);
					var testDto = metadata.Value<DateTimeOffset>("TestDTO");
					Assert.Equal(dto, testDto);
				}
			}
		}
示例#23
0
        public void WillNotSerializeEvents()
        {
            IOExtensions.DeleteDirectory("Data");
            try
            {
                using (var documentStore = new EmbeddableDocumentStore())
                {
                    documentStore.Configuration.DataDirectory = "Data";
                    documentStore.Conventions.CustomizeJsonSerializer = x => x.TypeNameHandling = TypeNameHandling.Auto;
                    documentStore.Initialize();

                    var bar = new Bar();
                    var foo = new Foo();
                    foo.PropertyChanged += bar.FooChanged;

                    using (var session = documentStore.OpenSession())
                    {
                        session.Store(foo);
                        session.SaveChanges();
                    }
                }
            }
            finally
            {
                IOExtensions.DeleteDirectory("Data");
            }
        }
示例#24
0
		public void ShouldWork()
		{
			using (var store = NewDocumentStore())
			{
				store.Conventions.IdentityTypeConvertors.Add(new UInt32Converter());
				using (var session = store.OpenSession())
				{
					var foo = new Foo() { Id = uint.MaxValue };
					foo.Related.Add(uint.MaxValue);
					session.Store(foo);
					var bar = new Bar { Id = uint.MaxValue };
					session.Store(bar);
					session.SaveChanges();
				}
				using (var session = store.OpenSession())
				{
					var foo = session.Query<Foo>()
						.Customize(x=>x.WaitForNonStaleResults())
						.ToList();
					var bar = session.Query<Bar>().ToList();
					//This line blows up
					var foobar = session.Query<Foo>().Include<Foo, Bar>(f => f.Related).ToList();
				}
			}
		}
		public void Export_And_Import_Retains_HiLoState()
		{
			using (var session = documentStore.OpenSession())
			{
				var foo = new Foo { Something = "something2" };
				Assert.Null(foo.Id);
				session.Store(foo);
				Assert.NotNull(foo.Id);
				session.SaveChanges();
			}

			var smugglerApi = new SmugglerApi(new RavenConnectionStringOptions { Url = "http://localhost:8079/" });
			smugglerApi.ExportData(new SmugglerOptions { File = DumpFile });
			Assert.True(File.Exists(DumpFile));

			using (var session = documentStore.OpenSession())
			{
				var hilo = session.Load<HiLoKey>("Raven/Hilo/foos");
				Assert.NotNull(hilo);
				Assert.Equal(32, hilo.Max);
			}

			server.Dispose();
			CreateServer();

			smugglerApi.ImportData(new SmugglerOptions { File = DumpFile });

			using (var session = documentStore.OpenSession())
			{
				var hilo = session.Load<HiLoKey>("Raven/Hilo/foos");
				Assert.NotNull(hilo);
				Assert.Equal(32, hilo.Max);
			}
		}
            public void ShouldSerialize()
            {
                // arrange
                var obj = new Foo
                {
                    Bar = new Bar
                    {
                        Baz = true,
                        Bazz = 123.4,
                        Bazzz = "hello",
                    },
                };

                // act
                var result = _serializer.Serialize(obj);

                // assert
                result.ShouldEqual(
@"{
  ""Bar"": {
    ""Baz"": true,
    ""Bazz"": 123.4,
    ""Bazzz"": ""hello""
  }
}");
            }
示例#27
0
        public void Instance()
        {
            Foo foo = new Foo();

            var fooReflection = foo.Reflection();

            #if !SILVERLIGHT
            // Silverlight does not allow access to private members through reflection

            Assert.Equal(foo.I, fooReflection.Get("i"));

            fooReflection.Set("i", 2);

            Assert.Equal(2, foo.I);

            Assert.Equal(2, fooReflection.Get("I"));
            #endif

            fooReflection.Set("I", 3);

            Assert.Equal(3, foo.I);

            Assert.Equal(3, fooReflection.Get("GetI"));

            fooReflection.Set("SetI", 4);

            Assert.Equal(4, foo.I);
        }
        public void WorkForTypesThatMuckAroundWithEquality()
        {
            var foo1 = new Foo();
            var foo2 = new Foo();

            Assert.That(_instanceTracker.InstanceNumber(foo1), Is.EqualTo(1));
            Assert.That(_instanceTracker.InstanceNumber(foo2), Is.EqualTo(2));
        }
        public void DefaultToListT()
        {
            var obj = new Foo { Bars = new Bar[] { new Bar { }, new Bar { } } };

            var clone = Serializer.DeepClone(obj);
            Assert.AreEqual(2, clone.Bars.Count);
            Assert.IsInstanceOfType(typeof(List<Bar>), clone.Bars);
        }
示例#30
0
            public void Should_Return_String()
            {
                var foo = new Foo() { DateField = DateTime.Now, StringField = "some string", IntegerField = 5 };

                var result = Serializer.ConvertToXml<Foo>(foo);

                Assert.IsNotNull(result);
            }