示例#1
0
            public async Task Should_delete_the_ninja_from_azure_table()
            {
                // Arrange
                var ninjaToDelete = CreateEntity(ClanName1);
                var clanName      = ninjaToDelete.PartitionKey;
                var ninjaKey      = ninjaToDelete.RowKey;

                TableStorageMock
                .SetupEnforceNinjaExistenceAsync(clanName, ninjaKey);
                TableStorageMock
                .Setup(x => x.DeleteOneAsync(clanName, ninjaKey))
                .ReturnsAsync(ninjaToDelete);

                // Act
                var result = await Client.DeleteAsync($"v1/ninja/{clanName}/{ninjaKey}");

                // Assert
                result.EnsureSuccessStatusCode();
                var ninja = await result.Content.ReadAsJsonObjectAsync <Ninja>();

                Assert.NotNull(ninja);
                AssertNinjaEntityEqualNinja(ninjaToDelete, ninja);
            }
示例#2
0
            public async Task Should_update_the_ninja_in_azure_table()
            {
                // Arrange
                var ninjaToUpdate = new Ninja
                {
                    Clan = new Clan {
                        Name = ClanName1
                    },
                    Key   = "Some UpdateAsync Ninja Key",
                    Name  = "My new name",
                    Level = 1234
                };
                var ninjaBody = ninjaToUpdate.ToJsonHttpContent();

                NinjaEntity updatedEntity = null;

                TableStorageMock
                .Setup(x => x.InsertOrMergeAsync(It.IsAny <NinjaEntity>()))
                .ReturnsAsync((NinjaEntity n) =>
                {
                    updatedEntity = n;
                    return(n);
                });
                TableStorageMock
                .SetupEnforceNinjaExistenceAsync(ClanName1, ninjaToUpdate.Key);

                // Act
                var result = await Client.PutAsync("v1/ninja", ninjaBody);

                // Assert
                result.EnsureSuccessStatusCode();
                var ninja = await result.Content.ReadAsJsonObjectAsync <Ninja>();

                Assert.NotNull(ninja);
                Assert.NotNull(updatedEntity);
                AssertNinjaEntityEqualNinja(updatedEntity, ninja);
            }