コード例 #1
0
        public void LoadDocTypesTest_RecursiveParent()
        {
            ISqlHelper fakeSql = Isolate.Fake.Instance <ISqlHelper>(Members.CallOriginal);

            IRecordsReader reader = Isolate.Fake.Instance <IRecordsReader>();

            Isolate.WhenCalled(() => reader.HasRecords).WillReturnRepeat(true, 3).AndThen().CallOriginal();
            Isolate.WhenCalled(() => reader.Read()).WillReturnRepeat(true, 3).AndThen().CallOriginal();
            Isolate.WhenCalled(() => reader.GetId()).WillReturn(2);
            Isolate.WhenCalled(() => reader.GetParentId()).WillReturn(1);

            Isolate.WhenCalled(() => reader.GetId()).WillReturn(1);
            Isolate.WhenCalled(() => reader.GetParentId()).WillReturn(3);

            Isolate.WhenCalled(() => reader.GetId()).WillReturn(3);
            Isolate.WhenCalled(() => reader.GetParentId()).WillReturn(-1);

            Isolate.WhenCalled(() => fakeSql.ExecuteReader(string.Empty)).WillReturn(reader);

            DocTypeObjectBuilder target = new DocTypeObjectBuilder(string.Empty);

            Isolate.WhenCalled(() => target.SqlHelper).WillReturn(fakeSql);
            Isolate.WhenCalled(() => target.GetProperties(0)).WillReturn(new System.Collections.Generic.List <DocTypeProperty>());
            Isolate.WhenCalled(() => target.BuildAssociations(0)).WillReturn(new System.Collections.Generic.List <DocTypeAssociation>());

            target.LoadDocTypes();

            Assert.AreEqual(3, target.DocumentTypes.Count);
            Assert.AreEqual(target.DocumentTypes[0].Id, target.DocumentTypes[1].ParentId);

            Isolate.Verify.WasCalledWithExactArguments(() => target.LoadParentDocType(3));
        }
コード例 #2
0
        public void LoadDocTypesTest_GenerateAssociations()
        {
            var sql    = Isolate.Fake.Instance <ISqlHelper>();
            var reader = Isolate.Fake.Instance <IRecordsReader>();

            DocTypeObjectBuilder target = new DocTypeObjectBuilder(string.Empty);

            Isolate.WhenCalled(() => target.SqlHelper).WillReturn(sql);
            Isolate.WhenCalled(() => target.GetProperties(0)).WillReturn(new System.Collections.Generic.List <DocTypeProperty>());

            Isolate.WhenCalled(() => sql.ExecuteReader(string.Empty)).WillReturn(reader);

            Isolate.WhenCalled(() => reader.HasRecords).WillReturn(true);
            Isolate.WhenCalled(() => reader.Read()).WillReturnRepeat(true, 2);
            Isolate.WhenCalled(() => reader.Read()).WillReturn(false);

            Isolate.WhenCalled(() => reader.GetInt("AllowedId")).WillReturn(1);

            target.LoadDocTypes();

            Isolate.Verify.WasCalledWithExactArguments(() => target.BuildAssociations(1));

            Assert.AreEqual(1, target.DocumentTypes.Count);
            Assert.AreEqual(1, target.DocumentTypes[0].Associations.Count);
            Assert.AreEqual(1, target.DocumentTypes[0].Associations[0].AllowedId);
        }