public async void Should_merge_the_entities()
            {
                // Arrange
                const string partitionKey               = "MergeAsync";
                const string rowKey                     = "MyKey";
                const string expectedSomePropValue      = "SomeFinalValue";
                const string expectedSomeOtherPropValue = "SomeOtherValue";
                await SomeOtherTestEntityRepository.InsertOrReplaceAsync(new SomeOtherTestEntity
                {
                    PartitionKey  = partitionKey,
                    RowKey        = rowKey,
                    ETag          = "*",
                    SomeOtherProp = expectedSomeOtherPropValue
                });

                // Act
                var result = await RepositoryUnderTest.MergeAsync(new SomeTestEntity
                {
                    PartitionKey = partitionKey,
                    RowKey       = rowKey,
                    ETag         = "*",
                    SomeProp     = expectedSomePropValue
                });

                // Assert
                var entity1 = await RepositoryUnderTest.ReadOneAsync(partitionKey, rowKey);

                var entity2 = await SomeOtherTestEntityRepository.ReadOneAsync(partitionKey, rowKey);

                Assert.NotNull(entity1);
                Assert.NotNull(entity2);
                Assert.Equal(expectedSomePropValue, entity1.SomeProp);
                Assert.Equal(expectedSomeOtherPropValue, entity2.SomeOtherProp);
            }
예제 #2
0
            public async Task Should_map_ReadOne_and_return_the_expected_ninja()
            {
                // Arrange
                var clanName      = "My clan";
                var ninjaKey      = "123FB950-57DB-4CD0-B4D1-7E6B00A6163A";
                var entity        = new NinjaEntity();
                var expectedNinja = new Ninja();

                NinjaEntityTableStorageRepositoryMock
                .Setup(x => x.ReadOneAsync(clanName, ninjaKey))
                .ReturnsAsync(entity)
                .Verifiable();
                NinjaMappingServiceMock
                .Setup(x => x.Map(entity))
                .Returns(expectedNinja)
                .Verifiable();

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(clanName, ninjaKey);

                // Assert
                NinjaMappingServiceMock
                .Verify(x => x.Map(entity), Times.Once);
                NinjaEntityTableStorageRepositoryMock
                .Verify(x => x.ReadOneAsync(clanName, ninjaKey), Times.Once);
                Assert.Same(expectedNinja, result);
            }
            public async void Should_replace_an_entity()
            {
                // Arrange
                const string partitionKey  = "ReplaceAsync";
                const string rowKey        = "MyKey";
                const string expectedValue = "SomeOtherValue";
                await RepositoryUnderTest.InsertOrReplaceAsync(new SomeTestEntity
                {
                    PartitionKey = partitionKey,
                    RowKey       = rowKey,
                    ETag         = "*",
                    SomeProp     = "SomeValue"
                });

                // Act
                var result = await RepositoryUnderTest.ReplaceAsync(new SomeTestEntity
                {
                    PartitionKey = partitionKey,
                    RowKey       = rowKey,
                    ETag         = "*",
                    SomeProp     = expectedValue
                });

                // Assert
                Assert.NotNull(result);
                var entity = await RepositoryUnderTest.ReadOneAsync(partitionKey, rowKey);

                Assert.Equal(expectedValue, entity.SomeProp);
            }
            public async void Should_insert_an_entity()
            {
                // Arrange
                const string partitionName = "InsertAsync";
                const string rowKey        = "MyKey";
                const string expectedValue = "SomeValue";
                var          entity        = new SomeTestEntity
                {
                    PartitionKey = partitionName,
                    RowKey       = rowKey,
                    SomeProp     = expectedValue
                };

                var persistedEntity = await RepositoryUnderTest.ReadOneAsync(partitionName, rowKey);

                if (persistedEntity != null)
                {
                    await RepositoryUnderTest.DeleteOneAsync(partitionName, rowKey);
                }

                // Act
                var result = await RepositoryUnderTest.InsertAsync(entity);

                // Assert
                Assert.NotNull(result);
                var dbResult = await RepositoryUnderTest.ReadOneAsync(partitionName, rowKey);

                Assert.NotNull(dbResult);
                Assert.Equal(expectedValue, dbResult.SomeProp);
            }
예제 #5
0
            public async Task Should_return_null_if_the_clan_does_not_exist()
            {
                // Arrange
                var unexistingClanName = "Unexisting clan";

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(unexistingClanName);

                // Assert
                Assert.Null(result);
            }
예제 #6
0
            public async Task ShouldReturnNullIfTheClanDoesNotExist()
            {
                //Arrange
                string clanName = "Not Exist Clan";

                //Act
                var result = await RepositoryUnderTest.ReadOneAsync(clanName);

                //Assert
                Assert.Null(result);
            }
            public async Task ReadOneAsync_Returns_Null_When_WorkoutDoesNotExist()
            {
                // Arrange
                const int id = 1;

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(id);

                // Assert
                Assert.Null(result);
            }
예제 #8
0
            public async Task Should_return_the_expected_clan()
            {
                // Arrange
                var expectedClan     = Clans[1];
                var expectedClanName = expectedClan.Name;

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(expectedClanName);

                // Assert
                Assert.Same(expectedClan, result);
            }
            public async Task ReadOneAsync_Returns_Workout()
            {
                // Arrange
                var expectedWorkout = new Workout {
                    Name = "Test workout 01"
                };

                TrainingPlanContextMock.Workouts.Add(expectedWorkout);
                await TrainingPlanContextMock.SaveChangesAsync();

                var id = expectedWorkout.Id;

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(id);

                // Assert
                Assert.Same(expectedWorkout, result);
            }
            public async void Should_delete_an_entity()
            {
                // Arrange
                const string partitionName = "DeleteOneAsync";
                const string rowKey        = "MyKey";
                var          entity        = new SomeTestEntity
                {
                    PartitionKey = partitionName,
                    RowKey       = rowKey
                };
                await RepositoryUnderTest.InsertOrReplaceAsync(entity);

                // Act
                var result = await RepositoryUnderTest.DeleteOneAsync(partitionName, rowKey);

                // Assert
                Assert.NotNull(result);
                var dbResult = await RepositoryUnderTest.ReadOneAsync(partitionName, rowKey);

                Assert.Null(dbResult);
            }
            public async void Should_return_an_entity()
            {
                // Arrange
                const string partitionName = "ReadOneAsync";
                const string rowKey        = "MyKey";
                const string expectedValue = "SomeValue";
                var          entity        = new SomeTestEntity
                {
                    PartitionKey = partitionName,
                    RowKey       = rowKey,
                    SomeProp     = expectedValue
                };
                await RepositoryUnderTest.InsertOrReplaceAsync(entity);

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(partitionName, rowKey);

                // Assert
                Assert.NotNull(result);
                Assert.Equal(partitionName, result.PartitionKey);
                Assert.Equal(rowKey, result.RowKey);
                Assert.Equal(expectedValue, result.SomeProp);
            }