Esempio n. 1
0
        public void Should_take_event_name_based_on_attribute()
        {
            var stubAggregate    = StubAggregate.Create("Test");
            var metadataProvider = new EventTypeMetadataProvider();
            var metadatas        = stubAggregate.UncommittedEvents.SelectMany(e => metadataProvider.Provide(stubAggregate, e.Data, MetadataCollection.Empty));

            var metadata = new MetadataCollection(metadatas);

            metadata.GetValue(MetadataKeys.EventName).Should().Be("StubCreated");
        }
        public void HandleIdentityChange_does_not_update_collection_if_does_not_contain_specified_item()
        {
            var members = new List<EdmProperty>();
            var memberCount = MetadataCollection<EntityType>.UseDictionaryCrossover + 1;

            for (var i = 0; i < memberCount; i++)
            {
                members.Add(EdmProperty.CreatePrimitive("P" + i, PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));
            }

            var collection = new MetadataCollection<EdmProperty>(members);
            Assert.Equal(memberCount, collection.Count);

            var property = EdmProperty.CreatePrimitive("MyProperty", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            property.Name = "MyNewProperty";
            collection.HandleIdentityChange(property, "MyProperty");

            Assert.Equal(memberCount, collection.Count);            
            Assert.False(collection.ContainsIdentity("MyProperty"));
            Assert.False(collection.ContainsIdentity("MyNewProperty"));

            property = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            property.Name = "MyProperty";
            collection.HandleIdentityChange(property, "P2");

            Assert.Equal(memberCount, collection.Count);            
            Assert.False(collection.ContainsIdentity("MyProperty"));
            Assert.True(collection.ContainsIdentity("P2"));
            Assert.NotSame(property, collection.GetValue("P2", ignoreCase: false));
        }
        public void Dictionaries_are_updated_when_HandleIdentityChange_is_called()
        {
            var members = new List<EdmProperty>();

            for (var i = 0; i < MetadataCollection<EntityType>.UseDictionaryCrossover + 1; i++)
            {
                members.Add(EdmProperty.CreatePrimitive("P" + i, PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));
            }

            var collection = new MetadataCollection<EdmProperty>(members);
            Assert.Equal(members.Count, collection.Count);

            collection.GetValue(collection[0].Identity, false);
            collection.GetValue(collection[0].Identity, true);

            Assert.True(collection.HasCaseSensitiveDictionary);
            Assert.True(collection.HasCaseInsensitiveDictionary);

            var item = collection[3];
            item.Name = "R3";
            collection.HandleIdentityChange(item, "P3");

            Assert.True(collection.HasCaseSensitiveDictionary);
            Assert.False(collection.HasCaseInsensitiveDictionary);

            Assert.Same(item, collection["R3"]);
        }