Ejemplo n.º 1
0
            public async Task Should_return_all_ninja_in_azure_table_partition()
            {
                // Arrange
                var expectedClanName    = ClanName2;
                var expectedNinja       = CreateEntities(amountOfNinjaToCreate: 2, clanName: expectedClanName).ToArray();
                var expectedNinjaLength = 2;

                TableStorageMock
                .Setup(x => x.ReadPartitionAsync(expectedClanName))
                .ReturnsAsync(expectedNinja);

                // Act
                var result = await Client.GetAsync($"v1/ninja/{expectedClanName}");

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

                Assert.NotNull(ninja);
                Assert.Equal(expectedNinjaLength, ninja.Length);
                Assert.Collection(ninja,
                                  n => AssertNinjaEntityEqualNinja(expectedNinja[0], n),
                                  n => AssertNinjaEntityEqualNinja(expectedNinja[1], n)
                                  );
            }
Ejemplo n.º 2
0
            public async Task Should_return_all_ninja_in_azure_table()
            {
                // Arrange
                var superClanNinja      = CreateEntities(amountOfNinjaToCreate: 2, clanName: ClanName1);
                var otherClanNinja      = CreateEntities(amountOfNinjaToCreate: 2, clanName: ClanName2);
                var all                 = superClanNinja.Union(otherClanNinja).ToArray();
                var expectedNinjaLength = 4;

                TableStorageMock
                .Setup(x => x.ReadAllAsync())
                .ReturnsAsync(all);

                // Act
                var result = await Client.GetAsync("v1/ninja");

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

                Assert.NotNull(ninja);
                Assert.Equal(expectedNinjaLength, ninja.Length);
                Assert.Collection(ninja,
                                  n => AssertNinjaEntityEqualNinja(all[0], n),
                                  n => AssertNinjaEntityEqualNinja(all[1], n),
                                  n => AssertNinjaEntityEqualNinja(all[2], n),
                                  n => AssertNinjaEntityEqualNinja(all[3], n)
                                  );
            }
Ejemplo n.º 3
0
            public async Task Should_create_the_ninja_in_azure_table()
            {
                // Arrange
                var ninjaToCreate = new Ninja
                {
                    Name  = "Bob",
                    Level = 6,
                    Key   = "12345",
                    Clan  = new Clan {
                        Name = ClanName1
                    }
                };
                var ninjaBody = ninjaToCreate.ToJsonHttpContent();

                var         mapper        = new Mappers.NinjaEntityToNinjaMapper();
                NinjaEntity createdEntity = null;

                TableStorageMock
                .Setup(x => x.InsertOrReplaceAsync(It.IsAny <NinjaEntity>()))
                .ReturnsAsync((NinjaEntity x) => {
                    createdEntity = x;
                    return(x);
                });

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

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

                Assert.NotNull(ninja);
                Assert.NotNull(createdEntity);
                AssertNinjaEntityEqualNinja(createdEntity, ninja);
            }
Ejemplo n.º 4
0
            public async Task Should_return_one_ninja_from_azure_table()
            {
                // Arrange
                var expectedNinja = CreateEntity(ClanName1);
                var clanName      = expectedNinja.PartitionKey;
                var ninjaKey      = expectedNinja.RowKey;

                TableStorageMock
                .Setup(x => x.ReadOneAsync(clanName, ninjaKey))
                .ReturnsAsync(expectedNinja);

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

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

                Assert.NotNull(ninja);
                AssertNinjaEntityEqualNinja(expectedNinja, ninja);
            }
Ejemplo n.º 5
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);
            }
Ejemplo n.º 6
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);
            }