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_removed_modified_event_should_be_called() { var subscriber = Substitute.For <IDummySubscriber>(); var item = new { Id = AutoFixture.Create <string>(), Str = AutoFixture.Create <string>(), Int = AutoFixture.Create <int>(), Obj = new { Value = AutoFixture.Create <string>() } }; var jObject = JObject.FromObject(item); var collection = new StreamCollection(_name); collection.Added(item.Id, jObject); collection.Modified += subscriber.React; // Act collection.Removed(item.Id); // Assert subscriber.Received() .React(Arg.Any <object>(), Arg.Is <StreamCollectionEventArgs>(args => args.ModificationType == ModificationType.Removed && args.Result == jObject )); }
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_does_exist_but_generic_is_not_of_type_thow() { var fixture = AutoFixture.Create <StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act Action action = () => collection.GetById <string>(fixture.Id); // Assert action.ShouldThrow <ArgumentException>(); }
public void When_object_does_exist_return_object() { var fixture = AutoFixture.Create <StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act var result = collection.GetById <StreamCollectionFixture>(fixture.Id); // Assert result.Should().Be(fixture); }
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_object_exists_object_should_exist() { 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)); var exists = collection.ContainsId(item.Id); // Assert exists.Should().BeTrue(); }
public void When_object_exists_object_should_exist() { 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)); var exists = collection.ContainsId(item.Id); // Assert exists.Should().BeTrue(); }
public async Task Login_with_email() { var email = AutoFixture.Create <string>(); var password = AutoFixture.Create <string>(); var payload = new { user = new { email }, password = new { digest = EncodingHelper.Sha256Hash(password), algorithm = EncodingHelper.Sha256 } }; var loginResult = AutoFixture.Create <LoginResult>(); var loginResponse = JObject.FromObject(new { result = loginResult }); _mockClient.CallAsync(Arg.Any <string>(), CancellationToken, Arg.Any <object[]>()) .ReturnsForAnyArgs(Task.FromResult(loginResponse)); IStreamCollection collection = new StreamCollection("users"); var user = JObject.FromObject(new { username = "" }); collection.Added(loginResult.UserId, user); _mockCollectionDatabase.WaitForObjectInCollectionAsync("users", loginResult.UserId, CancellationToken) .Returns(Task.FromResult(collection)); // Act await _driver.LoginWithEmailAsync(email, password); // Assert await _mockClient.ReceivedWithAnyArgs().CallAsync("login", CancellationToken, payload); }
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_objects_exists_return_jobject() { 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.GetJObjectById(item.Id); ((string)result["Id"]).Should().Be(item.Id); }
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_removed_modified_event_should_be_called() { var subscriber = Substitute.For<IDummySubscriber>(); var item = new { Id = AutoFixture.Create<string>(), Str = AutoFixture.Create<string>(), Int = AutoFixture.Create<int>(), Obj = new { Value = AutoFixture.Create<string>() } }; var jObject = JObject.FromObject(item); var collection = new StreamCollection(_name); collection.Added(item.Id, jObject); collection.Modified += subscriber.React; // Act collection.Removed(item.Id); // Assert subscriber.Received() .React(Arg.Any<object>(), Arg.Is<StreamCollectionEventArgs>(args => args.ModificationType == ModificationType.Removed && args.Result == jObject )); }
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_does_exist_but_generic_is_not_of_type_thow() { var fixture = AutoFixture.Create<StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act Action action = () => collection.GetById<string>(fixture.Id); // Assert action.ShouldThrow<ArgumentException>(); }
public void When_object_does_exist_return_object() { var fixture = AutoFixture.Create<StreamCollectionFixture>(); var collection = new StreamCollection(_name); collection.Added(fixture.Id, JObject.FromObject(fixture)); // Act var result = collection.GetById<StreamCollectionFixture>(fixture.Id); // Assert result.Should().Be(fixture); }
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); }
public void When_objects_exists_return_jobject() { 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.GetJObjectById(item.Id); ((string) result["Id"]).Should().Be(item.Id); }
public async Task Login_with_email() { var email = AutoFixture.Create<string>(); var password = AutoFixture.Create<string>(); var payload = new { user = new { email }, password = new { digest = EncodingHelper.Sha256Hash(password), algorithm = EncodingHelper.Sha256 } }; var loginResult = AutoFixture.Create<LoginResult>(); var loginResponse = JObject.FromObject(new { result = loginResult }); _mockClient.CallAsync(Arg.Any<string>(), CancellationToken, Arg.Any<object[]>()) .ReturnsForAnyArgs(Task.FromResult(loginResponse)); IStreamCollection collection = new StreamCollection("users"); var user = JObject.FromObject(new {username = ""}); collection.Added(loginResult.UserId, user); _mockCollectionDatabase.WaitForObjectInCollectionAsync("users", loginResult.UserId, CancellationToken) .Returns(Task.FromResult(collection)); // Act await _driver.LoginWithEmailAsync(email, password); // Assert await _mockClient.ReceivedWithAnyArgs().CallAsync("login", CancellationToken, payload); }