示例#1
0
        public async Task Update3Async()
        {
            ExpectException.Throws <ArgumentNullException>("*", () => _db.Persons3.UpdateAsync(null));

            // Get previous.
            var v = await _db.Persons3.GetAsync(5.ToGuid());

            Assert.NotNull(v);

            // Update testing.
            v.Id = 404.ToGuid();
            ExpectException.Throws <NotFoundException>("*", () => _db.Persons3.UpdateAsync(v));

            v.Id        = 5.ToGuid();
            v.Name     += "X";
            v.ChangeLog = null;
            v           = await _db.Persons3.UpdateAsync(v);

            Assert.NotNull(v);
            Assert.AreEqual(5.ToGuid(), v.Id);
            Assert.AreEqual("MikeX", v.Name);
            Assert.IsNotNull(v.ChangeLog);
            Assert.IsNotNull(v.ChangeLog.CreatedBy);
            Assert.IsNotNull(v.ChangeLog.CreatedDate);
            Assert.IsNotNull(v.ChangeLog.UpdatedBy);
            Assert.IsNotNull(v.ChangeLog.UpdatedDate);
        }
示例#2
0
 public void SetTrailerRowType_SameContentRecIdException()
 {
     ExpectException.Throws <ArgumentException>("The TrailerRecordIdentifier cannot be the same as the ContentRecordIdentifier.", () =>
     {
         var dff = new DelimitedFileFormat <Person>("X");
         dff.SetTrailerRowType <Trailer>("X");
     });
 }
示例#3
0
        public void C120_DoNotAllowMultipleMessages()
        {
            var sp = TestSetUp.CreateServiceProvider();

            ExpectException.Throws<EventSubscriberException>(
                "The 'EventDataSubscriberHost' does not AllowMultipleMessages; there were 2 event messages.",
                async () => await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(TestSub)).UseServiceProvider(sp).UseLoggerForAuditing()).ReceiveAsync(new EventData(), new EventData()));
        }
示例#4
0
 public void SetHeaderRowType_NoRecIdException()
 {
     ExpectException.Throws <ArgumentNullException>("The record identifier is required where the file is considered hierarchical.", () =>
     {
         var dff = new DelimitedFileFormat <Person>("X");
         dff.SetHeaderRowType <Header>();
     });
 }
示例#5
0
 public void SetHeaderRowType_SameAsContentException()
 {
     ExpectException.Throws <ArgumentException>("The HeaderRowType cannot be the same as the ContentRowType.", () =>
     {
         var dff = new DelimitedFileFormat <Person>("X");
         dff.SetHeaderRowType <Person>("H");
     });
 }
示例#6
0
 public void SetHeaderRowType_NoHierarchyException()
 {
     ExpectException.Throws <ArgumentException>("The record identifier can not be specified where the file is not considered hierarchical.", () =>
     {
         var dff = new DelimitedFileFormat <Person>();
         dff.SetHeaderRowType <Header>("H");
     });
 }
示例#7
0
 public void Prop_FalseValues_EmptyException()
 {
     ExpectException.Throws <ArgumentException>("There must be at least a single item for both the TrueValues and FalseValues properties.", () =>
     {
         var bc         = new BooleanConverter();
         bc.FalseValues = new string[] { };
     });
 }
示例#8
0
        public void Ctor_NoIEventSubscriber()
        {
            var sp = TestSetUp.CreateServiceProvider();

            ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp));
            ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, (Type[])null));
            ExpectException.Throws <ArgumentException>("*", () => EventSubscriberHostArgs.Create(sp, new Type[] { }));
        }
示例#9
0
 public void SetTrailerRowType_SameAsContentException()
 {
     ExpectException.Throws <InvalidOperationException>("The TrailerRowType cannot be the same as the ContentRowType.", () =>
     {
         var dff = new DelimitedFileFormat <Person>("X");
         dff.SetTrailerRowType <Person>("T");
     });
 }
        public void SetConverter_ViaInterface()
        {
            var pm = (IODataPropertyMapper) new ODataPropertyMapper <Person, Address>(x => x.Address);

            Assert.IsNull(pm.Converter);

            ExpectException.Throws <MapperException>("The PropertyMapper SrceType 'Address' and Converter SrceType 'Boolean' must match.",
                                                     () => pm.SetConverter(BooleanToYesNoConverter.Default));
        }
示例#11
0
 public void SetHeaderRowType_AlreadySetException()
 {
     ExpectException.Throws <InvalidOperationException>("The HeaderRowType cannot be set more than once.", () =>
     {
         var dff = new DelimitedFileFormat <Person>("X");
         dff.SetHeaderRowType <Header>("H", HeaderValidator.Default);
         dff.SetHeaderRowType <Header>("H", HeaderValidator.Default);
     });
 }
示例#12
0
        public void C110_TooManySubjectSubscribers()
        {
            var ed = new EventData<string> { Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST" };
            var sp = TestSetUp.CreateServiceProvider();

            ExpectException.Throws<EventSubscriberException>(
                "There are 2 IEventSubscriber instances subscribing to Subject 'Test.Blah.123' and Action 'CREATE'; there must be only a single subscriber.",
                async () => await new EventDataSubscriberHost(EventSubscriberHostArgs.Create(typeof(TestSub), typeof(TestSubS)).UseServiceProvider(sp).UseLoggerForAuditing()).ReceiveAsync(ed));
        }
示例#13
0
        public void C110_TooManySubjectSubscribers()
        {
            var ed = new EventData <string> {
                Subject = "Test.Blah.123", Action = "CREATE", Username = "******", Value = "TEST"
            };

            ExpectException.Throws <EventSubscriberException>(
                "There are 2 IEventSubscriber instances subscribing to Subject 'Test.Blah.123' and Action 'CREATE'; there must be only a single subscriber.",
                async() => await EventDataSubscriberHost.Create(new EventSubscriberHostArgs(TestSetUp.CreateLogger(), new TestSub(), new TestSubS())).ReceiveAsync(ed));
        }
示例#14
0
 public void Read_OnlyForHeaderException()
 {
     ExpectException.Throws <InvalidOperationException>("The ColumnNameHeader can only be used for a Header row.", () =>
     {
         using (var sr = new StringReader("Col1,Col2,Col3"))
         {
             var ff = new DelimitedFileFormat <ColumnNameHeader>();
             var fr = new FileReader <ColumnNameHeader>(sr, ff);
             fr.Read();
         }
     });
 }
示例#15
0
        public void SetMapper_ViaInterface()
        {
            var pm = (IODataPropertyMapper) new ODataPropertyMapper <Person, Address>(x => x.Address);

            Assert.IsNull(pm.Mapper);

            pm.SetMapper(new ODataMapper <Address>("Address"));
            Assert.IsNotNull(pm.Mapper);

            ExpectException.Throws <MapperException>("The PropertyMapper SrceType 'Address' has an ItemType of 'Address' which must be the same as the underlying EntityMapper SrceType 'Person'.",
                                                     () => pm.SetMapper(new EntityMapper <Person, Address>()));
        }
示例#16
0
        public async Task Get2Async()
        {
            ExpectException.Throws <ArgumentNullException>("*", () => _db.Persons2.GetAsync());
            ExpectException.Throws <NotSupportedException>("Only a single key value is currently supported.", () => _db.Persons2.GetAsync(1, 2));

            Assert.IsNull(await _db.Persons2.GetAsync(404.ToGuid()));

            var v = await _db.Persons2.GetAsync(1.ToGuid());

            Assert.IsNotNull(v);
            Assert.AreEqual("Rebecca", v.Name);
        }
示例#17
0
 public void WriteHeader_NoHeaderRowTypeException()
 {
     ExpectException.Throws <InvalidOperationException>("FileFormat has no corresponding HeaderRowType specified.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff = new DelimitedFileFormat <Data>();
             var fw = new FileWriter <Data>(sw, ff);
             fw.WriteHeader(new Header());
         }
     });
 }
        public void Execute_BothColumnAndHierarchyAttributesException()
        {
            ExpectException.Throws <InvalidOperationException>("Type 'BothColumnAndHierarchyAttributes' property 'Data' cannot specify both a FileColumnAttribute and FileHierarchyAttribute.", () =>
            {
                using (var sr = new StringReader("X"))
                {
                    var ff = new DelimitedFileFormat <BothColumnAndHierarchyAttributes>(FileFormatBase.TabCharacter);
                    var fr = new FileReader <BothColumnAndHierarchyAttributes>(sr, ff);

                    var result = fr.Read();
                }
            });
        }
示例#19
0
 public void Read_IsHierarchicalException()
 {
     ExpectException.Throws <InvalidOperationException>("The ColumnNameHeader cannot be used when the File Format is hierarchical.", () =>
     {
         using (var sr = new StringReader("Z"))
         {
             var ff = new DelimitedFileFormat <HierarchyDataA>("A");
             ff.SetHeaderRowType <ColumnNameHeader>("Z");
             var fr = new FileReader <HierarchyDataA>(sr, ff);
             fr.Read();
         }
     });
 }
        public void Execute_DuplicateRecordIdentifierException()
        {
            ExpectException.Throws <InvalidOperationException>("Type 'DuplicateRecordIdentifier' property 'C' FileHierarchyAttribute has a duplicate Record Identifier 'A' (must be unique within Type).", () =>
            {
                using (var sr = new StringReader("X"))
                {
                    var ff = new DelimitedFileFormat <DuplicateRecordIdentifier>(FileFormatBase.TabCharacter);
                    var fr = new FileReader <DuplicateRecordIdentifier>(sr, ff);

                    var result = fr.Read();
                }
            });
        }
示例#21
0
        public void FileReader_Read_ConverterNotFoundException()
        {
            ExpectException.Throws <InvalidOperationException>("FileColumnAttribute has TextValueConverterKey of 'Bool' is not found within the FileFormat.Converters.", () =>
            {
                using (var sr = new StringReader("Y,1"))
                {
                    var ff = new DelimitedFileFormat <BoolConverterData>();
                    ff.Converters.Add(new BooleanConverter());
                    var fr = new FileReader <BoolConverterData>(sr, ff);

                    var result = fr.Read();
                }
            });
        }
        public void Execute_IsLineNumberNotIntegerException()
        {
            ExpectException.Throws <InvalidOperationException>("FileColumnAttribute has IsLineNumber set to true; the underlying property type must be either Int32 or Int64.", () =>
            {
                using (var sr = new StringReader("X"))
                {
                    var ff = new DelimitedFileFormat <IsLineNumberNotInteger>(FileFormatBase.TabCharacter);
                    var fr = new FileReader <IsLineNumberNotInteger>(sr, ff);

                    var result = fr.Read();
                    Assert.Fail();
                }
            });
        }
示例#23
0
 public void Write_IsHierarchicalException()
 {
     ExpectException.Throws <InvalidOperationException>("The ColumnNameHeader cannot be used when the File Format is hierarchical.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff = new DelimitedFileFormat <HierarchyDataA>("A");
             ff.SetHeaderRowType <ColumnNameHeader>("Z");
             var fr = new FileWriter <HierarchyDataA>(sw, ff);
             fr.WriteHeader(ColumnNameHeader.Default);
         }
     });
 }
示例#24
0
 public void WriteHeader_DifferentHeaderRowTypeException()
 {
     ExpectException.Throws <ArgumentException>("Header Type must be the same as the specified FileFormat HeaderRowType.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff = new DelimitedFileFormat <Data>();
             var fw = new FileWriter <Data>(sw, ff);
             ff.SetHeaderRowType <Header>();
             fw.WriteHeader(new Trailer());
         }
     });
 }
示例#25
0
 public void Write_OnlyForHeaderException()
 {
     ExpectException.Throws <InvalidOperationException>("The ColumnNameHeader can only be used for a Header row.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff = new DelimitedFileFormat <ColumnNameHeader>();
             var fr = new FileWriter <ColumnNameHeader>(sw, ff);
             fr.Write(ColumnNameHeader.Default);
             Assert.Fail();
         }
     });
 }
示例#26
0
 public void Write_EndOfFileException()
 {
     ExpectException.Throws <InvalidOperationException>("Attempt made to write past the end of the file.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff = new DelimitedFileFormat <Data>();
             var fw = new FileWriter <Data>(sw, ff);
             fw.EndOfFile();
             fw.Write(new Data());
             Assert.Fail();
         }
     });
 }
示例#27
0
 public void WriteHeader_NotFirstRecordException()
 {
     ExpectException.Throws <InvalidOperationException>("A Header can only be written as the first record.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff = new DelimitedFileFormat <Data>();
             var fw = new FileWriter <Data>(sw, ff);
             ff.SetHeaderRowType <Header>();
             fw.Write(new Data());
             fw.WriteHeader(new Header());
         }
     });
 }
示例#28
0
        public async Task Delete2Async()
        {
            ExpectException.Throws <ArgumentNullException>("*", () => _db.Persons2.DeleteAsync());
            ExpectException.Throws <NotSupportedException>("Only a single key value is currently supported.", () => _db.Persons2.DeleteAsync(1, 2));

            ExpectException.Throws <NotFoundException>("*", () => _db.Persons2.DeleteAsync(404.ToGuid()));
            ExpectException.Throws <NotFoundException>("*", () => _db.Persons2.DeleteAsync(100.ToGuid()));
            await _db.Persons2.DeleteAsync(4.ToGuid());

            using (var r = await _db.Persons2.Container.ReadItemStreamAsync(4.ToGuid().ToString(), Microsoft.Azure.Cosmos.PartitionKey.None))
            {
                Assert.NotNull(r);
                Assert.AreEqual(System.Net.HttpStatusCode.NotFound, r.StatusCode);
            };
        }
示例#29
0
 public void WriteTrailer_WriteAfterTrailerException()
 {
     ExpectException.Throws <InvalidOperationException>("Attempt made to write past a Trailer row; Trailer must be the last record.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff = new DelimitedFileFormat <Data>();
             var fw = new FileWriter <Data>(sw, ff);
             ff.SetTrailerRowType <Trailer>();
             fw.WriteTrailer(new Trailer());
             fw.Write(new Data());
         }
     });
 }
示例#30
0
 public void Write_FileValidation_MustHaveTrailerRow_NoHeaderType()
 {
     ExpectException.Throws <InvalidOperationException>("FileFormat specifies FileValidation with MustHaveTrailerRow; no corresponding TrailerRowType specified.", () =>
     {
         var sb = new StringBuilder();
         using (var sw = new StringWriter(sb))
         {
             var ff            = new DelimitedFileFormat <Data>();
             var fw            = new FileWriter <Data>(sw, ff);
             ff.FileValidation = FileValidation.MustHaveTrailerRow;
             fw.EndOfFile();
             Assert.Fail();
         }
     });
 }