public void WhenUpsertAndEntityExists_ThenReplacesInRepository()
        {
            var entity = new TestDto {
                Id = "anupsertedid".ToIdentifier(), AStringValue = "anewvalue"
            };
            var fetchedEntity  = new CommandEntity("anid");
            var updatedEntity  = new CommandEntity("anid");
            var hydratedEntity = new TestDto {
                Id = "anid".ToIdentifier()
            };

            this.repository.Setup(repo =>
                                  repo.Retrieve("acontainername", It.IsAny <string>(),
                                                It.IsAny <RepositoryEntityMetadata>()))
            .Returns(fetchedEntity);
            this.repository.Setup(repo =>
                                  repo.Replace("acontainername", It.IsAny <string>(), It.IsAny <CommandEntity>()))
            .Returns(updatedEntity);

            var result = this.storage.Upsert(entity);

            result.Should().BeEquivalentTo(hydratedEntity);
            this.repository.Verify(repo =>
                                   repo.Retrieve("acontainername", "anupsertedid",
                                                 It.IsAny <RepositoryEntityMetadata>()));
            this.repository.Verify(repo =>
                                   repo.Replace("acontainername", "anupsertedid", It.IsAny <CommandEntity>()));
        }
        public void WhenUpsertAndEntityNotExists_ThenAddsToRepository()
        {
            var entity = new TestDto {
                Id = "anid".ToIdentifier()
            };
            var addedEntity = new CommandEntity("anid");

            this.repository.Setup(repo => repo.Retrieve("acontainername", "anid",
                                                        It.IsAny <RepositoryEntityMetadata>()))
            .Returns((CommandEntity)null);
            this.repository.Setup(repo => repo.Add(It.IsAny <string>(), It.IsAny <CommandEntity>()))
            .Returns(addedEntity);

            this.storage.Upsert(entity);

            this.repository.Verify(repo =>
                                   repo.Retrieve("acontainername", "anid",
                                                 It.IsAny <RepositoryEntityMetadata>()));
            this.repository.Verify(repo => repo.Add("acontainername", It.IsAny <CommandEntity>()));
        }