public void When_object_is_changed_merge_existing_values() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { OldValue = AutoFixture.Create <string>(), Value = AutoFixture.Create <string>() } }; var other = new { Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { OldVaue = item.Obj.OldValue, Value = AutoFixture.Create <string>(), NewValue = AutoFixture.Create <string>() }, NewValue = AutoFixture.Create <string>() }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, other); result.Int.Should().Be(other.Int); result.Str.Should().Be(other.Str); result.Obj.Should().Be(other.Obj); other.Should().NotBeSameAs(result); var result2 = collection.GetAnonymousTypeById(item.Id, item); result2.Id.Should().Be(item.Id); item.Should().NotBeSameAs(result2); }
public void When_an_empty_object_is_given_for_change_update_nothing() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var other = new { }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().Be(item); }
public void When_object_is_added_and_collection_is_contains_id_override_new_object() { var existing = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(existing.Id, JObject.FromObject(existing)); collection.Added(existing.Id, JObject.FromObject(item)); // Assert var result = collection.GetAnonymousTypeById(existing.Id, item); result.Should().Be(item); }
public void When_object_is_added_and_collection_is_empty_add_new_object() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().Be(item); }
public void When_object_deleted_remove_from_collection() { var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Removed(item.Id); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().BeNull(); }
public void When_object_deleted_remove_from_collection() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Removed(item.Id); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().BeNull(); }
public void When_an_empty_object_is_given_for_change_update_nothing() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var other = new { }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, item); result.Should().Be(item); }
public void When_object_is_changed_merge_existing_values() { var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { OldValue = AutoFixture.Create<string>(), Value = AutoFixture.Create<string>() } }; var other = new { Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { OldVaue = item.Obj.OldValue, Value = AutoFixture.Create<string>(), NewValue = AutoFixture.Create<string>() }, NewValue = AutoFixture.Create<string>() }; var collection = new StreamCollection(_name); // Act collection.Added(item.Id, JObject.FromObject(item)); collection.Changed(item.Id, JObject.FromObject(other)); // Assert var result = collection.GetAnonymousTypeById(item.Id, other); result.Int.Should().Be(other.Int); result.Str.Should().Be(other.Str); result.Obj.Should().Be(other.Obj); other.Should().NotBeSameAs(result); var result2 = collection.GetAnonymousTypeById(item.Id, item); result2.Id.Should().Be(item.Id); item.Should().NotBeSameAs(result2); }