public async Task GetAccountReturnsExistingAccountTest() { var provider = Guid.NewGuid().ToString(); var subject = Guid.NewGuid().ToString(); var sut = new AccountStore(Config.Storage); var firstActual = await sut.GetAccount(provider, subject, CancellationToken.None).ConfigureAwait(false); firstActual.IsNewAccount.Should().BeTrue(); var secondActual = await sut.GetAccount(provider, subject, CancellationToken.None).ConfigureAwait(false); secondActual.Should().BeEquivalentTo(firstActual, opt => opt.Excluding(x => x.IsNewAccount)); secondActual.IsNewAccount.Should().BeFalse(); }
public async Task GetAccountReturnsNewAccountWhenTableNotFoundTest() { // Retrieve storage account from connection-string var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString); // Create the table client var client = storageAccount.CreateCloudTableClient(); var table = client.GetTableReference("Accounts"); await table.DeleteIfExistsAsync().ConfigureAwait(false); var provider = Guid.NewGuid().ToString(); var subject = Guid.NewGuid().ToString(); var sut = new AccountStore(Config.Storage); var actual = await sut.GetAccount(provider, subject, CancellationToken.None).ConfigureAwait(false); actual.Should().NotBeNull(); actual.Id.Should().NotBeEmpty(); actual.Provider.Should().Be(provider); actual.Subject.Should().Be(subject); actual.IsNewAccount.Should().BeTrue(); }
public void GetAccountThrowsExceptionWithInvalidParametersTest(string provider, string subject) { var sut = new AccountStore(Config.Storage); Func <Task> action = async() => await sut.GetAccount(provider, subject, CancellationToken.None) .ConfigureAwait(false); action.Should().Throw <ArgumentException>(); }
public async Task GetAccountReturnsAccountWhenConflictFoundCreatingAccountOnAsynchronousRequestsTest() { var provider = Guid.NewGuid().ToString(); var subject = Guid.NewGuid().ToString(); var sut = new AccountStore(Config.Storage); var firstTask = sut.GetAccount(provider, subject, CancellationToken.None); var secondTask = sut.GetAccount(provider, subject, CancellationToken.None); var thirdTask = sut.GetAccount(provider, subject, CancellationToken.None); var tasks = new List <Task <AccountResult> > { firstTask, secondTask, thirdTask }; await Task.WhenAll(tasks).ConfigureAwait(false); var expected = firstTask.Result.Id; var actual = await sut.GetAccount(provider, subject, CancellationToken.None).ConfigureAwait(false); actual.Id.Should().Be(expected); tasks.Count(x => x.Result.IsNewAccount).Should().Be(1); tasks.Count(x => x.Result.IsNewAccount == false).Should().Be(2); }
public async Task GetAccountReturnsNewAccountWhenNotFoundTest() { var provider = Guid.NewGuid().ToString(); var subject = Guid.NewGuid().ToString(); var sut = new AccountStore(Config.Storage); var actual = await sut.GetAccount(provider, subject, CancellationToken.None).ConfigureAwait(false); actual.Should().NotBeNull(); actual.Id.Should().NotBeEmpty(); actual.Provider.Should().Be(provider); actual.Subject.Should().Be(subject); actual.IsNewAccount.Should().BeTrue(); }
public async Task DeleteAccountRemovesAccountTest() { var provider = Guid.NewGuid().ToString(); var subject = Guid.NewGuid().ToString(); var sut = new AccountStore(Config.Storage); await sut.GetAccount(provider, subject, CancellationToken.None).ConfigureAwait(false); await sut.DeleteAccount(provider, subject, CancellationToken.None).ConfigureAwait(false); // Retrieve storage account from connection-string var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString); // Create the client var client = storageAccount.CreateCloudTableClient(); var operation = TableOperation.Retrieve(provider, subject); var table = client.GetTableReference("Accounts"); var result = await table.ExecuteAsync(operation).ConfigureAwait(false); result.HttpStatusCode.Should().Be(404); }