Пример #1
0
        public async Task WriteMessageCreatesQueueMessageFromClassTest()
        {
            var queueName = Guid.NewGuid().ToString("N");
            var expected  = Model.Create <Profile>();

            var target = new ProfileStore(Config.Storage.ConnectionString, queueName);

            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);
            var client         = storageAccount.CreateCloudQueueClient();
            var queue          = client.GetQueueReference(queueName);

            try
            {
                await target.WriteMessage(expected, null, null, CancellationToken.None).ConfigureAwait(false);

                var queueItem = await queue.GetMessageAsync().ConfigureAwait(false);

                var storedData = queueItem.AsString;
                var actual     = JsonConvert.DeserializeObject <Profile>(storedData);

                actual.Should().BeEquivalentTo(expected);
            }
            finally
            {
                await queue.DeleteIfExistsAsync().ConfigureAwait(false);
            }
        }
Пример #2
0
        private async Task IsDeleted(Guid profileId, IIdentity identity)
        {
            var accountReference = new Account(identity.Name);
            var storageAccount   = CloudStorageAccount.Parse(Config.AzureConnectionString);
            var operation        = TableOperation.Retrieve <AccountAdapter>(accountReference.Provider, accountReference.Subject);

            var client = storageAccount.CreateCloudTableClient();
            var table  = client.GetTableReference("Accounts");

            var accountResult = await table.ExecuteAsync(operation).ConfigureAwait(false);

            accountResult.HttpStatusCode.Should().Be(404);

            var profileStore = new ProfileStore(Config.Storage);

            var storedProfile = await profileStore.GetProfile(profileId, CancellationToken.None).ConfigureAwait(false);

            storedProfile.Should().BeNull();

            var photoStore = new PhotoStore(Config.Storage);

            var storedPhotos = await photoStore.GetPhotos(profileId, CancellationToken.None).ConfigureAwait(false);

            storedPhotos.Should().BeEmpty();
        }
Пример #3
0
        public void StoreProfileThrowsExceptionWithNullProfileTest()
        {
            var sut = new ProfileStore(Config.Storage);

            Func <Task> action = async() => await sut.StoreProfile(null, CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentNullException>();
        }
Пример #4
0
        public void DeleteProfileThrowsExceptionWithEmptyIdTest()
        {
            var sut = new ProfileStore(Config.Storage);

            Func <Task> action = async() => await sut.DeleteProfile(Guid.Empty, CancellationToken.None)
                                 .ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
Пример #5
0
        public async Task DeleteProfileIgnoresProfileNotFoundTest()
        {
            var sut = new ProfileStore(Config.Storage);

            var actual = await sut.DeleteProfile(Guid.NewGuid(), CancellationToken.None)
                         .ConfigureAwait(false);

            actual.Should().BeNull();
        }
Пример #6
0
        public async Task BanProfileReturnsNullWhenProfileNotFoundTest()
        {
            var sut = new ProfileStore(Config.Storage);

            var actual = await sut.BanProfile(Guid.NewGuid(), DateTimeOffset.UtcNow, CancellationToken.None)
                         .ConfigureAwait(false);

            actual.Should().BeNull();
        }
Пример #7
0
        public async Task GetProfileReturnsNullWhenProfileNotFoundTest()
        {
            var profileId = Guid.NewGuid();

            var sut = new ProfileStore(Config.Storage);

            var actual = await sut.GetProfile(profileId, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeNull();
        }
Пример #8
0
        public async Task StoreProfileWritesProfileWithNonAsciiCharactersTest(string firstName, string lastName)
        {
            var profile = Model.Create <Profile>().Set(x => x.FirstName = firstName).Set(x => x.LastName = lastName);

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(profile, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.GetProfile(profile.Id, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers());
        }
Пример #9
0
        public async Task StoreProfileWritesProfileToStorageTest()
        {
            var profile = Model.Create <Profile>().Set(x => x.BannedAt = null);

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(profile, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.GetProfile(profile.Id, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers());
        }
Пример #10
0
        public async Task GetProfileReturnsStoredProfileTest()
        {
            var expected = Model.Create <Profile>();

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(expected, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.GetProfile(expected.Id, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(expected);
        }
Пример #11
0
        public async Task BanProfileReturnsNullWhenAlreadyBannedTest()
        {
            var profile  = Model.Create <Profile>().Set(x => x.BannedAt = DateTimeOffset.UtcNow);
            var bannedAt = DateTimeOffset.UtcNow.AddDays(-2);

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(profile, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.BanProfile(profile.Id, bannedAt, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeNull();
        }
Пример #12
0
        public async Task BanProfileUpdatesExistingProfileTest()
        {
            var profile  = Model.Create <Profile>().Set(x => x.BannedAt = null);
            var bannedAt = DateTimeOffset.UtcNow.AddDays(-2);

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(profile, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.BanProfile(profile.Id, bannedAt, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(profile, opt => opt.Excluding(x => x.BannedAt));
            actual.BannedAt.Should().Be(bannedAt);
        }
Пример #13
0
        public async Task DeleteProfileRemovesProfileTest()
        {
            var profile = Model.Create <Profile>();

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(profile, CancellationToken.None).ConfigureAwait(false);

            var deletedProfile = await sut.DeleteProfile(profile.Id, CancellationToken.None)
                                 .ConfigureAwait(false);

            deletedProfile.Should().BeEquivalentTo(profile);

            var actual = await sut.GetProfile(profile.Id, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeNull();
        }
Пример #14
0
        public async Task GetProfileResultsDoesNotReturnHiddenProfilesTest()
        {
            var first = Model.Create <Profile>().Set(x => x.Status = ProfileStatus.Available)
                        .Set(x => x.BannedAt = null);
            var second = Model.Create <Profile>().Set(x => x.Status = ProfileStatus.Hidden).Set(x => x.BannedAt = null);

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(first, CancellationToken.None).ConfigureAwait(false);

            await sut.StoreProfile(second, CancellationToken.None).ConfigureAwait(false);

            var actual = (await sut.GetProfileResults(CancellationToken.None).ConfigureAwait(false)).ToList();

            actual.Should().Contain(x => x.Id == first.Id);
            actual.Should().NotContain(x => x.Id == second.Id);
        }
Пример #15
0
        public async Task GetProfileReturnsNullWhenTableNotFoundTest()
        {
            // 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("Profiles");

            await table.DeleteIfExistsAsync().ConfigureAwait(false);

            var sut = new ProfileStore(Config.Storage);

            var actual = await sut.GetProfile(Guid.NewGuid(), CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeNull();
        }
Пример #16
0
        public async Task StoreProfileCreatesTableAndWritesProfileWhenTableNotFoundTest()
        {
            // 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("Profiles");

            await table.DeleteIfExistsAsync().ConfigureAwait(false);

            var profile = Model.Create <Profile>().Set(x => x.BannedAt = null);

            var sut = new ProfileStore(Config.Storage);

            await sut.StoreProfile(profile, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.GetProfile(profile.Id, CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers());
        }