Example #1
0
        public void ValidateNotSpecifiedFieldAreNullProperties()
        {
            string             rawResponse       = @"
{
total_rows: 123,
offset: 40,
rows: [
{
  id: ""1"",
  key: ""ido.ran"",
  value: null,
  doc: {
    _id: ""1"",
    _rev: ""1-1edc9b67751f21e58895635c4eb47456"",
    email: ""*****@*****.**"",
    password: ""AAABBBCCC"",
    passwordSalt: ""123123123"",
    roles: [
      ""Admin""
    ],
    tenants: [
      ""20130722094352-TenantA""
    ],
    username: ""ido.ran"",
    $type: ""user""
  }
}
]
}";
            var                couchDBClientMock = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          user = subject.View <UserModel>("fake_not_used").SingleOrDefault();

            Assert.IsNull(user.FirstName);
        }
Example #2
0
        public void ValidateFieldNamesWithTwoWords()
        {
            string rawResponse = @"
{
total_rows: 248,
offset: 0,
rows: [
{
id: ""20130722094352-TenantA"",
key: [
""1"",
1
],
value: null,
doc: {
_id: ""20130722094352-TenantA"",
_rev: ""1-9aa586de15bb6784b48600741a8bf841"",
defaultLanguage: ""he-IL"",
name: ""Tenant-A"",
planID: ""Free30"",
users: [
""1""
],
$type: ""tenant""
}
}
]
}";

            var couchDBClientMock      = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            TenantModel        tenant  = subject.View <TenantModel>("fake_not_used").SingleOrDefault();

            Assert.AreEqual("he-IL", tenant.DefaultLanguage);
        }
Example #3
0
        public void LoadUserWithSingleAssociateTenant()
        {
            string rawResponse = @"
{
total_rows: 248,
offset: 0,
rows: [
{
id: ""1"",
key: [
""1"",
0
],
value: null,
doc: {
  _id: ""1"",
  _rev: ""1-1edc9b67751f21e58895635c4eb47456"",
  email: ""*****@*****.**"",
  password: ""AAABBBCCC"",
  passwordSalt: ""123123123"",
  roles: [
  ""Admin""
  ],
  username: ""ido.ran"",
  $type: ""user""
}
},
{
id: ""20130722094352-TenantA"",
key: [
""1"",
1
],
value: null,
doc: {
  _id: ""20130722094352-TenantA"",
  _rev: ""1-9aa586de15bb6784b48600741a8bf841"",
  defaultLanguage: ""he-IL"",
  name: ""Tenant-A"",
  planID: ""Free30"",
  users: [
  ""1""
  ],
  $type: ""tenant""
}
}
]
}";

            var couchDBClientMock      = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          user    = subject
                                         .View <UserModel>("fake_not_used")
                                         .AssociatedCollection(x => x.Tenants, 1)
                                         .SingleOrDefault();
            TenantModel tenant = user.Tenants.Single();

            Assert.IsNotNull(tenant);
        }
Example #4
0
 public void Up(CouchDBContextImpl context)
 {
     if (expectation == MigrationExcpectation.NotToRun)
     {
         Assert.Fail("Migration " + name + " should not have run but it was");
     }
     runCount++;
 }
Example #5
0
 public MigratorUnderTest(
     CouchDBContextImpl context,
     RequiredMigrations requiredMigrations,
     ExistMigrations existMigrations)
     : base(context, requiredMigrations)
 {
     this.existMigrations = existMigrations;
 }
        internal static Serializer CreateSerializer(Type entityTypeToSerialize)
        {
            CouchDBContextImpl context = new CouchDBContextImpl(null);

            context.Mapping.MapDocTypeToEntity("e", entityTypeToSerialize);
            Serializer subject = context.Serializer;

            return(subject);
        }
        private void WriteToOneReference(object entity, JObject doc)
        {
            object relatedEntity = PropertyInfo.GetValue(entity);

            if (!Serializer.IsNull(relatedEntity))
            {
                string relatedEntityId = CouchDBContextImpl.GetEntityInstanceId(relatedEntity);
                doc.Add(JsonFieldName, relatedEntityId);
            }
        }
Example #8
0
        public static CouchDBContextImpl BuildContextForTest(CouchDBClientAdapterMock couchDBClientMock)
        {
            var context = new CouchDBContextImpl(couchDBClientMock);

            context.Mapping.MapDocTypeToEntity("user", typeof(UserModel));
            context.Mapping.MapDocTypeToEntity("tenant", typeof(TenantModel));
            context.Mapping.MapDocTypeToEntity("plan", typeof(PlanModel));

            return(context);
        }
Example #9
0
        public void LoadExistMultipleResults_SingleItemFromView_Exception()
        {
            string             rawResponse       = @"
{
total_rows: 123,
offset: 40,
rows: [
{
  id: ""1"",
  key: ""ido.ran"",
  value: null,
  doc: {
    _id: ""1"",
    _rev: ""1-1edc9b67751f21e58895635c4eb47456"",
    email: ""*****@*****.**"",
    password: ""AAABBBCCC"",
    passwordSalt: ""123123123"",
    roles: [
      ""Admin""
    ],
    tenants: [
      ""20130722094352-TenantA""
    ],
    username: ""ido.ran"",
    $type: ""user""
  }
},
{
  id: ""2"",
  key: ""ido.ran"",
  value: null,
  doc: {
    _id: ""2"",
    _rev: ""1-2edc9b67751f21e58895635c4eb47456"",
    email: ""*****@*****.**"",
    password: ""AAABBBCCC"",
    passwordSalt: ""123123123"",
    roles: [
      ""Admin""
    ],
    tenants: [
      ""20130722094352-TenantA""
    ],
    username: ""ido.ran"",
    $type: ""user""
  }
}
]
}";
            var                couchDBClientMock = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          user = subject.View <UserModel>("fake_not_used").SingleOrDefault();

            Assert.IsNull(user);
        }
        private static void PrepareForUpdate(out CouchDBContextImpl subject, out UserModel userToUpdate)
        {
            var bulkUpdaterMock = new BulkUpdaterMock();

            bulkUpdaterMock.AddMockResponse(new BulkResponseRow("1", "2-123-Updated", null, null));

            var couchDBClientMock = new CouchDBClientAdapterMock(RawResponseWithOneTenant, bulkUpdaterMock);

            subject      = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            userToUpdate = subject.View <UserModel>("fake_not_used").SingleOrDefault();
        }
        private void CreateDirectAssociationCollection(object proxy, JToken doc, CouchDBContextImpl context)
        {
            JArray jArr = Serializer.GetJArray(PropertyInfo, doc);

            if (jArr != null)
            {
                Array clrArr = Serializer.ResolveArray(typeof(string), jArr);

                context.Serializer.SetDirectAssoicationCollectionProperty(proxy, PropertyInfo, clrArr);
            }
        }
Example #12
0
        public void DeleteEntityMarkItForDeletion()
        {
            var couchDBClientMock      = new CouchDBClientAdapterMock(SingleUserRawResponse);
            CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          user    = subject.View <UserModel>("fake_not_used").SingleOrDefault();

            subject.Delete(user);

            DocumentState actual   = subject.DocumentManager.DocInfo(user.UserModelID).State;
            DocumentState expected = DocumentState.Delete;

            Assert.AreEqual(expected, actual);
        }
Example #13
0
        public void LoadNotExistSingleItemFromView()
        {
            string             rawResponse       = @"
{
total_rows: 123,
offset: 40,
rows: []
}";
            var                couchDBClientMock = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          user = subject.View <UserModel>("fake_not_used").Key("yoval.b").SingleOrDefault();

            Assert.IsNull(user);
        }
Example #14
0
        public void DeleteEntityAddedToBulkUpdater()
        {
            var bulkUpdaterMock        = new BulkUpdaterMock();
            var couchDBClientMock      = new CouchDBClientAdapterMock(SingleUserRawResponse, bulkUpdaterMock);
            CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          user    = subject.View <UserModel>("fake_not_used").SingleOrDefault();

            subject.Delete(user);

            subject.SaveChanges();

            Assert.AreEqual(1, bulkUpdaterMock.EntitiesToDelete.Count);
            Assert.AreEqual("1", bulkUpdaterMock.EntitiesToDelete[0]);
        }
Example #15
0
        public void NoMigrationToExecute()
        {
            var requiredMigrations = new RequiredMigrations();

            requiredMigrations.Add(new MigrationMock("001Migration", MigrationExcpectation.NotToRun));

            var existMigrations = new ExistMigrations();

            existMigrations.Add(new ExistMigrationInfo("001Migration"));

            var context = new CouchDBContextImpl(null);
            var subject = new MigratorUnderTest(context, requiredMigrations, existMigrations);

            subject.Migrate();

            EnsureExpectedMigrationRan(requiredMigrations);
        }
        private void CreateReferenceProxies(
            object proxy, JToken doc, string id,
            PreProcessInfo preProcess, OdmViewProcessingOptions processingOptions, bool emptyProxy,
            CouchDBContextImpl context)
        {
            AssociationAttribute associationAttr = AssociationAttribute.GetSingle(PropertyInfo);

            if (associationAttr == null)
            {
                if (emptyProxy)
                {
                    CreateDirectAssociationCollection(proxy, doc, context);
                }
            }
            else
            {
                CreateInverseAssociationCollection(proxy, doc, id, preProcess, associationAttr, processingOptions, context);
            }
        }
        private void CreateInverseAssociationCollection(
            object proxy, JToken doc, string id,
            PreProcessInfo preProcess, AssociationAttribute associationAttr,
            OdmViewProcessingOptions processingOptions, CouchDBContextImpl context)
        {
            object keyPart;

            if (processingOptions.AssoicateCollectionsToLoad.TryGetValue(PropertyInfo.Name, out keyPart))
            {
                Type elementType = PropertyInfo.PropertyType.GenericTypeArguments[0];

                string[] inverseKeys =
                    preProcess.Rows
                    .Where(x => x.EntityType.Equals(elementType) && x.Key.MatchRelatedId(id, keyPart))
                    .Select(x => x.Id)
                    .ToArray();

                context.Serializer.SetInverseAssociationCollectionInternal(proxy, PropertyInfo, associationAttr, inverseKeys);
            }
        }
Example #18
0
        public void LoadReduceViewToEntities()
        {
            string             rawResponse       = @"
{
rows: [
{
key: ""20121010170328-מבנה-ארגוני"",
value: {
yes: 49,
no: 3,
count: 52
}
},
{
key: ""20120821121948-Test2"",
value: {
yes: 4,
no: 4,
count: 8
}
},
{
key: ""20120814132737-שאלון-לבדיקה-1"",
value: {
yes: 14,
no: 66,
count: 80
}
}
]
}";
            var                couchDBClientMock = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);

            ReduceEntity[] results = subject.ReduceView <ReduceEntity>("fake_not_used").ToArray();
            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.Length);
        }
        private static CouchDocInfo GetCleanDocInfo()
        {
            string             rawResponse       = @"
{
total_rows: 123,
offset: 40,
rows: [
{
  id: ""1"",
  key: ""ido.ran"",
  value: null,
  doc: {
    _id: ""1"",
    _rev: ""1-1edc9b67751f21e58895635c4eb47456"",
    email: ""*****@*****.**"",
    password: ""AAABBBCCC"",
    passwordSalt: ""123123123"",
    roles: [
      ""Admin""
    ],
    tenants: [
      ""20130722094352-TenantA""
    ],
    username: ""ido.ran"",
    $type: ""user""
  }
}
]
}";
            var                couchDBClientMock = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl subject           = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          userToUpdate      = subject.View <UserModel>("fake_not_used").SingleOrDefault();

            CouchDocInfo docInfo = subject.DocumentManager.DocInfo("1");

            return(docInfo);
        }
 public abstract void Read(object entity, JToken doc, string id,
                           PreProcessInfo preProcess, OdmViewProcessingOptions processingOptions, bool emptyProxy,
                           CouchDBContextImpl context);
Example #21
0
        public void LoadMultipleUserWithSingleAssociateTenant()
        {
            string rawResponse = @"
{
total_rows: 248,
offset: 0,
rows: [
{
id: ""1"",
key: [
""1"",
0
],
value: null,
doc: {
_id: ""1"",
_rev: ""1-1edc9b67751f21e58895635c4eb47456"",
email: ""*****@*****.**"",
password: ""AAABBBCCC"",
passwordSalt: ""123123123"",
roles: [
""Admin""
],
tenants: [
""20130722094352-TenantA""
],
username: ""ido.ran"",
$type: ""user""
}
},
{
id: ""20130722094352-TenantA"",
key: [
""1"",
1
],
value: null,
doc: {
_id: ""20130722094352-TenantA"",
_rev: ""1-9aa586de15bb6784b48600741a8bf841"",
defaultLanguage: ""he-IL"",
name: ""Tenant-A"",
planID: ""Free30"",
users: [
""1""
],
$type: ""tenant""
}
},
{
id: ""10"",
key: [
""10"",
0
],
value: null,
doc: {
_id: ""10"",
_rev: ""1-a24d2f93d829d6a4901ea2767cf6b67c"",
email: ""*****@*****.**"",
password: ""9AC256B12CD5000CBCA395EB15B7872E5C8C3F4E"",
passwordSalt: ""CS0KHNC0ukhG9LzJDh+WI0WZzoyRC5GCwWA6UGJOAbY="",
tenants: [
""20121224110842-shakira""
],
username: ""*****@*****.**"",
$type: ""user""
}
},
{
id: ""20121224110842-shakira"",
key: [
""10"",
1
],
value: null,
doc: {
_id: ""20121224110842-shakira"",
_rev: ""1-d786ce65b8694a4c2d3a3b77b43be131"",
defaultLanguage: ""he"",
name: ""shakira"",
planID: ""Free30"",
users: [
""10"",
""26""
],
$type: ""tenant""
}
}
]
}";

            var couchDBClientMock           = new CouchDBClientAdapterMock(rawResponse);
            CouchDBContextImpl      subject = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            IEnumerable <UserModel> users   = subject.View <UserModel>("fake_not_used");

            Assert.AreEqual(2, users.Count());
        }
 public override void Read(object entity, JToken doc, string id, PreProcessInfo preProcess,
                           OdmViewProcessingOptions processingOptions, bool emptyProxy, CouchDBContextImpl context)
 {
     CreateReferenceProxies(entity, doc, id, preProcess, processingOptions, emptyProxy, context);
 }
Example #23
0
        public void ReadToOneRelatedEntitiesOfSingleSourceEntity()
        {
            string rawResponse       = @"
{
total_rows: 123,
offset: 40,
rows: [
{
  id: ""1"",
  key: ""ido.ran"",
  value: null,
  doc: {
    _id: ""1"",
    _rev: ""1-1edc9b67751f21e58895635c4eb47456"",
    email: ""*****@*****.**"",
    password: ""AAABBBCCC"",
    passwordSalt: ""123123123"",
    planID: ""Plan20"",
    roles: [
      ""Admin""
    ],
    tenants: [
      ""20130722094352-TenantA""
    ],
    username: ""ido.ran"",
    $type: ""user""
  }
}
]
}";
            var    couchDBClientMock = new CouchDBClientAdapterMock(rawResponse);

            couchDBClientMock.AddGetDocumentResponse(
                @"
{
total_rows: 241,
offset: 0,
rows: [
{
id: ""Plan20"",
key: ""Plan20"",
value: {
rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6""
},
doc: {
_id: ""Plan20"",
_rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6"",
currency: ""USD"",
maxEmployees: 30,
name: ""Plan20"",
price: 20,
$type: ""plan""
}
}
]
}
");

            CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock);
            UserModel          user    = subject.View <UserModel>("fake_not_used").SingleOrDefault();

            Assert.IsNull(user.Plan);
            subject.LoadRelated(user, cfg => cfg.One(x => x.Plan));
            Assert.IsNotNull(user.Plan);
        }
Example #24
0
 public override void Read(object entity, JToken doc, string id,
                           PreProcessInfo preProcess, OdmViewProcessingOptions processingOptions, bool emptyProxy, CouchDBContextImpl context)
 {
     // Not reloading value if this is not empty proxy.
     if (emptyProxy)
     {
         ReadValueType(entity, doc);
     }
 }
 public override void Read(object entity, JToken doc, string id, PreProcessInfo preProcess, OdmViewProcessingOptions processingOptions, bool emptyProxy, CouchDBContextImpl context)
 {
     // TODO: implement this.
 }
Example #26
0
        public void ReadToOneRelatedEntitiesOfMultipleSourceEntity()
        {
            string rawResponse       = @"
{
total_rows: 123,
offset: 40,
rows: [
{
  id: ""1"",
  key: ""ido.ran"",
  value: null,
  doc: {
    _id: ""1"",
    _rev: ""1-1edc9b67751f21e58895635c4eb47456"",
    email: ""*****@*****.**"",
    password: ""AAABBBCCC"",
    passwordSalt: ""123123123"",
    planID: ""Plan20"",
    roles: [
      ""Admin""
    ],
    tenants: [
      ""20130722094352-TenantA""
    ],
    username: ""ido.ran"",
    $type: ""user""
  },
  id: ""2"",
  key: ""doron.shavit"",
  value: null,
  doc: {
    _id: ""2"",
    _rev: ""2-2eb16b67751f21e58895635c4eb47456"",
    email: ""*****@*****.**"",
    password: ""AAABBBCCC"",
    passwordSalt: ""123123123"",
    planID: ""Free30"",
    roles: [
      ""Admin""
    ],
    tenants: [
      ""20130722094352-TenantA""
    ],
    username: ""ido.ran"",
    $type: ""user""
  }
}
]
}";
            var    couchDBClientMock = new CouchDBClientAdapterMock(rawResponse);

            couchDBClientMock.AddGetDocumentResponse(
                @"
{
total_rows: 241,
offset: 0,
rows: [
{
id: ""Plan20"",
key: ""Plan20"",
value: {
rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6""
},
doc: {
_id: ""Plan20"",
_rev: ""1-cdbf10a8cfb9c76119bd84706347a5e6"",
currency: ""USD"",
maxEmployees: 30,
name: ""Plan20"",
price: 20,
$type: ""plan""
}
},
{
id: ""Free30"",
key: ""Free30"",
value: {
rev: ""1-86604726db035c16d8bc32ec6762377c""
},
doc: {
_id: ""Free30"",
_rev: ""1-86604726db035c16d8bc32ec6762377c"",
currency: ""USD"",
maxEmployees: 30,
name: ""Free"",
price: 0,
$type: ""plan""
}
}
]
}
");

            CouchDBContextImpl subject = ContextTestHelper.BuildContextForTest(couchDBClientMock);

            UserModel[] users = subject.View <UserModel>("fake_not_used").ToArray();

            subject.LoadRelated(users, cfg => cfg.One(x => x.Plan));
            Assert.IsTrue(users.All(x => x.Plan != null));
        }
Example #27
0
        /// <summary>
        /// Assert the modified documents count in the DocumentManager.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="expectedCount"></param>
        /// <param name="message"></param>
        public static void ModifiedDocumentsCount(CouchDBContextImpl context, int expectedCount, string message = null)
        {
            int modifiedDocCount = context.DocumentManager.GetModifiedDocuments().Length;

            Assert.AreEqual(expectedCount, modifiedDocCount, message);
        }
 private static void UpdateSingleDocument(out CouchDBContextImpl subject, out UserModel userToUpdate)
 {
     PrepareForUpdate(out subject, out userToUpdate);
     userToUpdate.FirstName = "Yotam";
 }
 public override void Read(object entity, JToken doc, string id, PreProcessInfo preProcess,
                           OdmViewProcessingOptions processingOptions, bool emptyProxy, CouchDBContextImpl context)
 {
     ReadArray(entity, doc);
 }
Example #30
0
 public abstract void Up(CouchDBContextImpl context);