コード例 #1
0
        public void WhenUpsertAndEntityExists_ThenReplacesInRepository()
        {
            var entity = new TestDomainEntity("anupsertedid".ToIdentifier())
            {
                AStringValue = "anewvalue"
            };
            var fetchedEntity  = new CommandEntity("anid");
            var updatedEntity  = new CommandEntity("anid");
            var hydratedEntity = new TestDomainEntity("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);
            this.domainFactory.Setup(df =>
                                     df.RehydrateEntity(It.IsAny <Type>(), It.IsAny <IReadOnlyDictionary <string, object> >()))
            .Returns(hydratedEntity);

            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>()));
        }
コード例 #2
0
        public void WhenUpsertAndEntityNotExists_ThenAddsToRepository()
        {
            var entity      = new TestDomainEntity("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>()));
        }