Пример #1
0
        public void ShouldDelegateConvertEntityIdToDocumentId()
        {
            string providedEntityId = null;
            Type providedEntityType = null;

            var entityConfig = new EntityConfig(
                typeof(Entity),
                entityIdToDocumentId: (entityId, entityType, documentType) => {
                    providedEntityId = entityId;
                    providedEntityType = entityType;
                    return "doc1";
                }
            );

            var returnedDocId = entityConfig.ConvertEntityIdToDocumentId("entity1");

            Assert.Equal(returnedDocId, "doc1");
            Assert.Equal("entity1", providedEntityId);
            Assert.Equal(typeof(Entity), providedEntityType);
        }
Пример #2
0
        public void ShouldDelegateGetEntityId()
        {
            object gettingEntity = null;

            var idMemberMock = new Mock<ISpecialMember>();
            idMemberMock
                .Setup(m => m.GetValue(It.IsAny<object>()))
                .Returns<object>(e => { gettingEntity = e; return "doc1"; });

            var entityConfig = new EntityConfig(typeof(Entity), idMember: idMemberMock.Object);

            object entity = Entity.CreateStandard();
            string id = entityConfig.GetId(entity);

            Assert.Equal("doc1", id);
            Assert.Equal(entity, gettingEntity);
        }
Пример #3
0
 public void ShouldDelegateDocumentTypeGeneration()
 {
     var entityConfig = new EntityConfig(typeof(Entity), entityTypeToDocumentType: entityType => "docType1");
     Assert.Equal("docType1", entityConfig.DocumentType);
 }
Пример #4
0
        public void ShouldThrowOnNullInputToGetRevision()
        {
            var entityConfig = new EntityConfig(typeof(Entity));

            Assert.Throws<ArgumentNullException>(() => entityConfig.GetRevision(null));
        }
Пример #5
0
        public void ShouldThrowOnNullInputToSetId()
        {
            var entityConfig = new EntityConfig(typeof(Entity));

            Assert.Throws<ArgumentNullException>(() => entityConfig.SetId(null, "entity1"));
            Assert.Throws<ArgumentNullException>(() => entityConfig.SetId(Entity.CreateStandard(), null));
            Assert.Throws<ArgumentNullException>(() => entityConfig.SetId(Entity.CreateStandard(), string.Empty));
        }
Пример #6
0
        public void ShouldThrowOnIncorrectEntityTypeOnSetterAndGetterMethods()
        {
            var entityConfig = new EntityConfig(typeof(Entity));

            Assert.Throws<ArgumentException>(() => entityConfig.GetRevision(new EntityWithoutRevision()));
            Assert.Throws<ArgumentException>(() => entityConfig.GetId(new EntityWithoutRevision()));
            Assert.Throws<ArgumentException>(() => entityConfig.SetRevision(new EntityWithoutRevision(), "rev1"));
            Assert.Throws<ArgumentException>(() => entityConfig.SetId(new EntityWithoutRevision(), "entity1"));
        }
Пример #7
0
        public void ShouldThrowOnNullInputToConvertEntityIdToDocumentId()
        {
            var entityConfig = new EntityConfig(typeof(Entity));

            Assert.Throws<ArgumentNullException>(() => entityConfig.ConvertEntityIdToDocumentId(null));
            Assert.Throws<ArgumentNullException>(() => entityConfig.ConvertEntityIdToDocumentId(string.Empty));
        }
Пример #8
0
        public void ShouldReturnEmptyIgnoredMembersOnNullReturnedFromConvention()
        {
            var idMember = Mock.Of<ISpecialMember>(sm => sm.IsDefined == true && sm.RawMemberInfo == null);
            var revMember = Mock.Of<ISpecialMember>(sm => sm.IsDefined == true && sm.RawMemberInfo == null);

            var entityConfig = new EntityConfig(typeof(Entity), idMember: idMember, revisionMember: revMember);
            Assert.NotNull(entityConfig.IgnoredMembers);
            Assert.Equal(0, entityConfig.IgnoredMembers.Count());
        }
Пример #9
0
        public void ShouldDelegateSetEnityRevision()
        {
            string setRev = null;
            object settingEntity = null;

            var revisionMemberMock = new Mock<ISpecialMember>();
            revisionMemberMock
            .Setup(m => m.SetValue(It.IsAny<object>(), It.IsAny<string>()))
            .Callback<object, string>((e, rev) => { setRev = rev; settingEntity = e; });

            var entityConfig = new EntityConfig(typeof(Entity), revisionMember: revisionMemberMock.Object);

            object entity = Entity.CreateStandard();
            entityConfig.SetRevision(entity, "rev1");

            Assert.Equal("rev1", setRev);
            Assert.Equal(entity, settingEntity);
        }
Пример #10
0
        public void ShouldDelegateSetEnityId()
        {
            string setId = null;
            object settingEntity = null;

            var idMemberMock = new Mock<ISpecialMember>();
            idMemberMock
                .Setup(m => m.SetValue(It.IsAny<object>(), It.IsAny<string>()))
                .Callback<object, string>((e, id) => { setId = id; settingEntity = e; });

            var entityConfig = new EntityConfig(typeof(Entity), idMember: idMemberMock.Object);

            object entity = Entity.CreateStandard();
            entityConfig.SetId(entity, "doc1");

            Assert.Equal("doc1", setId);
            Assert.Equal(entity, settingEntity);
        }
Пример #11
0
        public void ShouldDelegateGetIgnoredMembers()
        {
            var thisMethodInfo = GetType().GetMethod("ShouldDelegateGetIgnoredMembers");
            var idMember = Mock.Of<ISpecialMember>(sm => sm.IsDefined == true && sm.RawMemberInfo == thisMethodInfo);
            var revMember = Mock.Of<ISpecialMember>(sm => sm.IsDefined == false);

            var entityConfig = new EntityConfig(typeof(Entity), idMember: idMember, revisionMember: revMember);

            Assert.Contains(thisMethodInfo, entityConfig.IgnoredMembers);
        }
Пример #12
0
        public void ShouldDelegateGetEntityRevision()
        {
            object gettingEntity = null;

            var revisionMemberMock = new Mock<ISpecialMember>();
            revisionMemberMock
                .Setup(m => m.GetValue(It.IsAny<object>()))
                .Returns<object>(e => { gettingEntity = e; return "rev1"; });

            var entityConfig = new EntityConfig(typeof(Entity), revisionMember: revisionMemberMock.Object);

            object entity = Entity.CreateStandard();
            var revision = entityConfig.GetRevision(entity);

            Assert.Equal("rev1", revision);
            Assert.Equal(entity, gettingEntity);
        }