Ejemplo n.º 1
0
        public void CannotChangeAuthorForExistsNote()
        {
            // Arrange
            var note = new HmmNote
            {
                Author      = _user,
                Description = "testing note",
                Subject     = "testing note is here",
                Content     = "<root><time>2017-08-01</time></root>",
                Catalog     = new NoteCatalog()
            };

            CurrentTime = new DateTime(2021, 4, 4, 8, 15, 0);
            _manager.Create(note);

            Assert.True(_manager.ProcessResult.Success);
            var savedRec = NoteRepository.GetEntities().FirstOrDefault();

            Assert.NotNull(savedRec);
            Assert.Equal("jfang", savedRec.Author.AccountName);

            // change the note render
            var newUser = LookupRepo.GetEntities <Author>().FirstOrDefault(u => u.AccountName != "jfang");

            Assert.NotNull(newUser);
            note.Author = newUser;

            // Act
            var processResult = new ProcessingResult();
            var result        = _validator.IsValidEntity(note, processResult);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 2
0
        public void Can_Delete_Note()
        {
            // Arrange
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author      = _author,
                Catalog     = _catalog,
                Description = "testing note",
                Subject     = "testing note is here",
                Content     = xmlDoc.InnerXml,
            };

            NoteRepository.Add(note);
            Assert.True(NoteRepository.ProcessMessage.Success);

            // Act
            var result = NoteRepository.Delete(note);

            // Assert
            Assert.True(NoteRepository.ProcessMessage.Success);
            Assert.True(result);
            Assert.False(NoteRepository.GetEntities().Any());
        }
Ejemplo n.º 3
0
        public void Cannot_Delete_NonExists_Note()
        {
            // Arrange
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author      = _author,
                Catalog     = _catalog,
                Description = "testing note",
                Subject     = "testing note is here",
                Content     = xmlDoc.InnerXml,
            };

            NoteRepository.Add(note);
            Assert.True(NoteRepository.ProcessMessage.Success);

            // change the note id to create a new note
            var orgId = note.Id;

            note.Id = 2;

            // Act
            var result = NoteRepository.Delete(note);

            // Assert
            Assert.False(NoteRepository.ProcessMessage.Success);
            Assert.False(result);

            // do this just to make clear up code pass
            note.Id = orgId;
        }
Ejemplo n.º 4
0
        public async Task <HmmNote> UpdateAsync(HmmNote note)
        {
            if (!_validator.IsValidEntity(note, ProcessResult))
            {
                return(null);
            }

            // make sure not update note which get cached in current session
            var curNote = await GetNoteByIdAsync(note.Id);

            if (curNote == null)
            {
                ProcessResult.AddErrorMessage($"Cannot find note {note.Id} ");
                return(null);
            }

            curNote.Subject          = note.Subject;
            curNote.Content          = note.Content;
            curNote.IsDeleted        = note.IsDeleted;
            curNote.Description      = note.Description;
            curNote.LastModifiedDate = _dateProvider.UtcNow;
            var ret = await _noteRepo.UpdateAsync(curNote);

            if (ret == null)
            {
                ProcessResult.PropagandaResult(_noteRepo.ProcessMessage);
            }

            return(ret);
        }
Ejemplo n.º 5
0
        public void Cannot_Delete_Catalog_With_Note_Associated()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };
            var savedCatalog = CatalogRepository.Add(catalog);

            var note = new HmmNote
            {
                Subject          = "Testing subject",
                Content          = "Testing content",
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Author           = _author,
                Catalog          = savedCatalog
            };

            NoteRepository.Add(note);

            // Act
            var result = CatalogRepository.Delete(catalog);

            // Assert
            Assert.False(result, "Error: deleted catalog with note attached to it");
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Ejemplo n.º 6
0
        public void Can_Update_Note_Content()
        {
            // Arrange
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author      = _author,
                Catalog     = _catalog,
                Description = "testing note",
                Subject     = "testing note is here",
                Content     = xmlDoc.InnerXml,
            };

            NoteRepository.Add(note);
            Assert.True(NoteRepository.ProcessMessage.Success);

            // Act
            var newXml = new XmlDocument();

            newXml.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><GasLog></GasLog>");
            note.Content = newXml.InnerXml;
            var savedRec = NoteRepository.Update(note);

            // Assert
            Assert.NotNull(savedRec);
            Assert.True(savedRec.Id >= 1, "savedRec.Id >=1");
            Assert.True(savedRec.Id == note.Id, "savedRec.Id == note.Id");
            Assert.Equal(newXml.InnerXml, savedRec.Content);
            Assert.NotEqual(xmlDoc.InnerXml, savedRec.Content);
        }
Ejemplo n.º 7
0
        public void Can_Update_Note_Catalog()
        {
            // Arrange
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author           = _author,
                Catalog          = _catalog,
                Description      = "testing note",
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Subject          = "testing note is here",
                Content          = xmlDoc.InnerXml
            };

            NoteRepository.Add(note);
            Assert.True(NoteRepository.ProcessMessage.Success);

            // changed the note catalog
            note.Catalog = CatalogRepository.GetEntities().FirstOrDefault(cat => !cat.IsDefault);

            // Act
            var savedRec = NoteRepository.Update(note);

            // Assert
            Assert.NotNull(savedRec);
            Assert.NotNull(savedRec.Catalog);
            Assert.NotNull(note.Catalog);
            Assert.Equal("Gas Log", savedRec.Catalog.Name);
            Assert.Equal("Gas Log", note.Catalog.Name);
        }
Ejemplo n.º 8
0
        public void Can_Update_Note()
        {
            // Arrange - note with null content
            var note = new HmmNote
            {
                Author  = _user,
                Subject = "Testing note",
                Content = "Testing content with < and >",
            };
            var crtTime = new DateTime(2021, 4, 4, 8, 15, 0);
            var mdfTime = new DateTime(2021, 4, 4, 8, 30, 0);

            CurrentTime = crtTime;
            _manager.Create(note);
            var savedNote = _manager.GetNoteById(note.Id);

            Assert.Equal(savedNote.Version, note.Version);

            // Act
            CurrentTime       = mdfTime;
            savedNote.Subject = "new note subject";
            savedNote.Content = "This is new note content";
            var updatedNote = _manager.Update(savedNote);

            // Assert
            Assert.True(_manager.ProcessResult.Success);
            Assert.NotNull(updatedNote);
            Assert.Equal("new note subject", updatedNote.Subject);
            Assert.Equal(updatedNote.CreateDate, crtTime);
            Assert.Equal(updatedNote.LastModifiedDate, mdfTime);
            Assert.NotEqual(updatedNote.Version, note.Version);
            Assert.False(note.IsDeleted);
        }
Ejemplo n.º 9
0
        public void Cannot_Update_Invalid_Note()
        {
            // Arrange
            var note = new HmmNote
            {
                Author      = _user,
                Description = "testing note",
                Subject     = "testing note is here",
                Content     = "<root><time>2017-08-01</time></root>"
            };

            CurrentTime = new DateTime(2021, 4, 4, 8, 15, 0);
            _manager.Create(note);

            Assert.True(_manager.ProcessResult.Success);
            var savedRec = NoteRepository.GetEntities().FirstOrDefault();

            Assert.NotNull(savedRec);
            Assert.Equal("jfang", savedRec.Author.AccountName);

            // change the note render
            var newUser = LookupRepo.GetEntities <Author>().FirstOrDefault(u => u.AccountName != "jfang");

            Assert.NotNull(newUser);
            note.Author = newUser;
            _testValidator.GetInvalidResult = true;

            // Act
            savedRec = _manager.Update(note);

            // Assert
            Assert.False(_manager.ProcessResult.Success);
            Assert.Null(savedRec);
            Assert.False(note.IsDeleted);
        }
Ejemplo n.º 10
0
        public void Note_Must_Has_Valid_Author()
        {
            // Arrange
            var note = new HmmNote
            {
                Author  = _author,
                Subject = "Test name",
                Content = "Test NameSpace",
                Catalog = _catalog
            };

            // Act

            var processResult = new ProcessingResult();
            var result        = _validator.IsValidEntity(note, processResult);

            // Assert
            Assert.True(result);

            // Arrange
            note = new HmmNote
            {
                Subject = "Test name",
                Content = "Test NameSpace",
                Catalog = _catalog
            };

            // Act

            processResult = new ProcessingResult();
            result        = _validator.IsValidEntity(note, processResult);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 11
0
        public void Can_Valid_Xml_Content_Against_Schema(string content, string comment, bool expectSuccess, bool expectWarning, bool expectError)
        {
            // Arrange
            var noteContent = string.Format(NoteXmlTextBase, XmlNamespace, content);
            var note        = new HmmNote
            {
                Id               = 1,
                Author           = _author,
                Subject          = AutomobileConstant.AutoMobileRecordSubject,
                Content          = noteContent,
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Description      = comment
            };

            // Act
            var discount = _noteSerializer.GetEntity(note);

            // Assert
            Assert.Equal(expectSuccess, _noteSerializer.ProcessResult.Success);
            Assert.Equal(expectWarning, _noteSerializer.ProcessResult.HasWarning);
            Assert.Equal(expectError, _noteSerializer.ProcessResult.HasError);
            if (_noteSerializer.ProcessResult.Success)
            {
                Assert.NotNull(discount);
            }
            else
            {
                Assert.Null(discount);
            }
        }
Ejemplo n.º 12
0
        public void Can_Get_GasLog_By_Parse_Valid_Note_Xml()
        {
            // Arrange
            Assert.NotNull(_defaultCar);
            Assert.NotNull(_defaultDiscount);
            var xmlDoc = XDocument.Parse($"<?xml version=\"1.0\" encoding=\"utf-16\" ?><Note xmlns=\"{XmlNamespace}\"><Content><GasLog><Date>2021-08-18T00:00:00.0000000</Date><Distance><Dimension><Value>250</Value><Unit>Kilometre</Unit></Dimension></Distance><CurrentMeterReading><Dimension><Value>13500</Value><Unit>Kilometre</Unit></Dimension></CurrentMeterReading><Gas><Volume><Value>50</Value><Unit>Liter</Unit></Volume></Gas><Price><Money><Value>1.30</Value><Code>CAD</Code></Money></Price><GasStation>Costco</GasStation><Discounts><Discount><Amount><Money><Value>0.8</Value><Code>CAD</Code></Money></Amount><Program>{_defaultDiscount.Id}</Program></Discount></Discounts><Automobile>{_defaultCar.Id}</Automobile><Comment>This is a comment</Comment><CreateDate>2021-10-17T00:00:00.0000000</CreateDate></GasLog></Content></Note>");
            var note   = new HmmNote
            {
                Id               = 1,
                Author           = _author,
                Subject          = AutomobileConstant.GasLogRecordSubject,
                Content          = xmlDoc.ToString(SaveOptions.DisableFormatting),
                CreateDate       = DateProvider.UtcNow,
                LastModifiedDate = DateProvider.UtcNow
            };

            var gasLogExpected = new GasLog
            {
                Id                  = 1,
                Date                = new DateTime(2021, 8, 18),
                Car                 = _defaultCar,
                Distance            = 250d.GetKilometer(),
                CurrentMeterReading = 13500d.GetKilometer(),
                Gas                 = 50d.GetLiter(),
                Price               = 1.3m.GetCad(),
                Station             = "Costco",
                Discounts           = new List <GasDiscountInfo>
                {
                    new()
                    {
                        Amount  = 0.8m.GetCad(),
                        Program = _defaultDiscount
                    }
                },
Ejemplo n.º 13
0
        public void Cannot_Add_Note_With_NonExist_Author(Author author)
        {
            // Arrange - null author for note
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author           = author,
                Catalog          = _catalog,
                Description      = "testing note",
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Subject          = "testing note is here",
                Content          = xmlDoc.InnerXml
            };

            // Act
            var savedRec = NoteRepository.Add(note);

            // Assert
            Assert.Null(savedRec);
            Assert.False(NoteRepository.GetEntities().Any());
            Assert.False(NoteRepository.ProcessMessage.Success);
            Assert.Single(NoteRepository.ProcessMessage.MessageList);
        }
Ejemplo n.º 14
0
        public void CanAddNoteWithNonExistCatalogDefaultCatalogApplied(NoteCatalog catalog)
        {
            // Arrange - null catalog for note
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author           = _author,
                Catalog          = catalog,
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Subject          = "testing note is here",
                Content          = xmlDoc.InnerXml
            };

            // Act
            var savedRec = NoteRepository.Add(note);

            // Assert
            Assert.NotNull(savedRec);
            Assert.True(savedRec.Id > 0, "savedRec.Id>0");
            Assert.True(savedRec.Id == note.Id, "savedRec.Id==note.Id");
            Assert.NotNull(savedRec.Catalog);
            Assert.Equal("DefaultNoteCatalog", savedRec.Catalog.Name);
        }
Ejemplo n.º 15
0
        public override T GetEntity(HmmNote note)
        {
            if (note == null)
            {
                ProcessResult.AddWaningMessage("Null note found when try to serializing entity to note", true);
            }

            return(default);
Ejemplo n.º 16
0
        public void Cannot_Add_Null_Note()
        {
            // Arrange
            HmmNote note = null;

            // Act
            // Asset
            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Throws <ArgumentNullException>(() => NoteRepository.Add(note));
        }
Ejemplo n.º 17
0
        public void SubjectMustHasValidContentLength()
        {
            // Arrange
            var note = new HmmNote
            {
                Author      = _user,
                Description = "testing note",
                Subject     = "",
                Content     = "<root><time>2017-08-01</time></root>",
                Catalog     = new NoteCatalog()
            };

            // Act
            var processResult = new ProcessingResult();
            var result        = _validator.IsValidEntity(note, processResult);

            // Assert
            Assert.False(result);

            // Arrange
            note = new HmmNote
            {
                Author      = _user,
                Description = "testing note",
                Subject     = GetRandomString(1001),
                Content     = "<root><time>2017-08-01</time></root>",
                Catalog     = new NoteCatalog()
            };

            // Act
            processResult = new ProcessingResult();
            result        = _validator.IsValidEntity(note, processResult);

            // Assert
            Assert.False(result);

            // Arrange
            note = new HmmNote
            {
                Author      = _user,
                Description = "testing note",
                Subject     = GetRandomString(15),
                Content     = "<root><time>2017-08-01</time></root>",
                Catalog     = new NoteCatalog()
            };

            // Act
            processResult = new ProcessingResult();
            result        = _validator.IsValidEntity(note, processResult);

            // Assert
            Assert.True(result);
        }
Ejemplo n.º 18
0
        public void Cannot_Delete_Author_With_Note_Associated()
        {
            // Arrange
            var render = new NoteRender
            {
                Name        = "DefaultRender",
                Namespace   = "NameSpace",
                IsDefault   = true,
                Description = "Description"
            };
            var savedRender = RenderRepository.Add(render);

            var catalog = new NoteCatalog
            {
                Name        = "DefaultCatalog",
                Render      = savedRender,
                Schema      = "testScheme",
                IsDefault   = false,
                Description = "Description"
            };
            var savedCatalog = CatalogRepository.Add(catalog);

            var author = new Author
            {
                AccountName = "glog",
                Description = "testing user",
                IsActivated = true
            };
            var savedUser = AuthorRepository.Add(author);

            var note = new HmmNote
            {
                Subject          = string.Empty,
                Content          = string.Empty,
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Author           = savedUser,
                Catalog          = savedCatalog
            };

            NoteRepository.Add(note);

            // Act
            var result = AuthorRepository.Delete(author);

            // Assert
            Assert.False(result, "Error: deleted user with note");
            Assert.False(AuthorRepository.ProcessMessage.Success);
            Assert.Single(AuthorRepository.ProcessMessage.MessageList);
        }
Ejemplo n.º 19
0
        public async Task <HmmNote> CreateAsync(HmmNote note)
        {
            if (!_validator.IsValidEntity(note, ProcessResult))
            {
                return(null);
            }

            note.CreateDate       = _dateProvider.UtcNow;
            note.LastModifiedDate = _dateProvider.UtcNow;
            var ret = await _noteRepo.AddAsync(note);

            if (ret == null)
            {
                ProcessResult.PropagandaResult(_noteRepo.ProcessMessage);
            }
            return(ret);
        }
Ejemplo n.º 20
0
        public void NoteCatalogMustValid()
        {
            // Arrange
            var note = new HmmNote
            {
                Author      = _user,
                Description = "testing note",
                Subject     = "testing note is here",
                Content     = "<root><time>2017-08-01</time></root>",
                Catalog     = null
            };

            // Act
            var processResult = new ProcessingResult();
            var result        = _validator.IsValidEntity(note, processResult);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 21
0
        public void Can_Get_Right_Xml_With_Null_Note_Content_To_DataSource()
        {
            // Arrange - note with null content
            var note = new HmmNote
            {
                Author  = _user,
                Subject = "Testing note",
                Content = null
            };
            var xmlDoc = XDocument.Parse($"<?xml version=\"1.0\" encoding=\"utf-16\" ?><Note xmlns=\"{CoreConstants.DefaultNoteNamespace}\"><Content></Content></Note>");

            // Act
            var newNote = _noteSerializer.GetNote(note);

            // Assert
            Assert.True(_noteSerializer.ProcessResult.Success);
            Assert.Equal(newNote.Content, xmlDoc.ToString(SaveOptions.DisableFormatting));
            Assert.NotNull(newNote);
        }
Ejemplo n.º 22
0
        public override GasLog GetEntity(HmmNote note)
        {
            try
            {
                var(gasLogRoot, ns) = GetEntityRoot(note, AutomobileConstant.GasLogRecordSubject);
                if (gasLogRoot == null)
                {
                    return(null);
                }
                _ = int.TryParse(gasLogRoot.Element(ns + "Automobile")?.Value, out var carId);
                var car = _autoManager.GetEntityById(carId);

                var gasLog = new GasLog
                {
                    Date                = GetDate(gasLogRoot.Element(ns + "Date")),
                    Id                  = note.Id,
                    Car                 = car,
                    Station             = gasLogRoot.Element(ns + "GasStation")?.Value,
                    Distance            = gasLogRoot.Element(ns + "Distance")?.GetDimension() ?? 0.GetKilometer(),
                    CurrentMeterReading = gasLogRoot.Element(ns + "CurrentMeterReading")?.GetDimension() ?? 0.GetKilometer(),
                    Gas                 = gasLogRoot.Element(ns + "Gas")?.GetVolume() ?? 0d.GetDeciliter(),
                    Price               = gasLogRoot.Element(ns + "Price")?.GetMoney() ?? 0m.GetCad(),
                    CreateDate          = GetDate(gasLogRoot.Element(ns + "CreateDate")),
                    Comment             = gasLogRoot.Element(ns + "Comment")?.Value,
                    AuthorId            = note.Author.Id
                };

                var discounts = GetDiscountInfos(gasLogRoot.Element(ns + "Discounts"), ns);
                if (discounts.Any())
                {
                    gasLog.Discounts = discounts;
                }

                return(gasLog);
            }
            catch (Exception e)
            {
                ProcessResult.WrapException(e);
                throw;
            }
        }
        public void Can_Get_Automobile_By_Parse_Valid_Note_Xml()
        {
            // Arrange
            var xmlDoc = XDocument.Parse($"<?xml version=\"1.0\" encoding=\"utf-16\" ?><Note xmlns=\"{XmlNamespace}\"><Content><Automobile><Maker>Subaru</Maker><Brand>Outback</Brand><Year>2017</Year><Color>Blue</Color><Pin>135</Pin><Plate>BCTT208</Plate><MeterReading>1234535</MeterReading></Automobile></Content></Note>");
            var note   = new HmmNote
            {
                Id               = 1,
                Author           = _author,
                Subject          = AutomobileConstant.AutoMobileRecordSubject,
                Content          = xmlDoc.ToString(SaveOptions.DisableFormatting),
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now
            };

            var autoExpected = new AutomobileInfo
            {
                Id           = 1,
                Maker        = "Subaru",
                Brand        = "Outback",
                Year         = "2017",
                Color        = "Blue",
                Pin          = "135",
                Plate        = "BCTT208",
                MeterReading = 1234535,
            };

            // Act
            var auto = _noteSerializer.GetEntity(note);

            // Assert
            Assert.True(_noteSerializer.ProcessResult.Success);
            Assert.NotNull(auto);
            Assert.Equal(autoExpected.Id, auto.Id);
            Assert.Equal(autoExpected.Maker, auto.Maker);
            Assert.Equal(autoExpected.Brand, auto.Brand);
            Assert.Equal(autoExpected.Year, auto.Year);
            Assert.Equal(autoExpected.Color, auto.Color);
            Assert.Equal(autoExpected.Pin, auto.Pin);
            Assert.Equal(autoExpected.Plate, auto.Plate);
            Assert.Equal(_author.Id.ToString(), auto.AuthorId.ToString());
        }
Ejemplo n.º 24
0
        public static HmmNote Clone(this HmmNote source, HmmNote targetNote = null)
        {
            if (source == null)
            {
                return(null);
            }

            if (targetNote == null)
            {
                var target = new HmmNote
                {
                    Id               = source.Id,
                    Subject          = source.Subject,
                    Content          = source.Content,
                    Description      = source.Description,
                    Author           = source.Author.Clone(),
                    Catalog          = source.Catalog.Clone(),
                    CreateDate       = source.CreateDate,
                    IsDeleted        = source.IsDeleted,
                    LastModifiedDate = source.LastModifiedDate,
                    Version          = source.Version
                };
                return(target);
            }
            else
            {
                targetNote.Id               = source.Id;
                targetNote.Subject          = source.Subject;
                targetNote.Content          = source.Content;
                targetNote.Description      = source.Description;
                targetNote.Author           = source.Author.Clone();
                targetNote.Catalog          = source.Catalog.Clone();
                targetNote.CreateDate       = source.CreateDate;
                targetNote.IsDeleted        = source.IsDeleted;
                targetNote.LastModifiedDate = source.LastModifiedDate;
                targetNote.Version          = source.Version;

                return(targetNote);
            }
        }
Ejemplo n.º 25
0
        public void Cannot_Update_NonExits_Note()
        {
            // Arrange - non exists id
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author      = _author,
                Catalog     = _catalog,
                Description = "testing note2",
                Subject     = "testing note is here",
                Content     = xmlDoc.InnerXml,
            };

            NoteRepository.Add(note);

            // Act
            var orgId = note.Id;

            note.Id = 2;
            var savedRec = NoteRepository.Update(note);

            // Assert
            Assert.False(NoteRepository.ProcessMessage.Success);
            Assert.Null(savedRec);

            // Arrange - invalid id
            note.Id = 0;

            // Act
            savedRec = NoteRepository.Update(note);

            // Assert
            Assert.False(NoteRepository.ProcessMessage.Success);
            Assert.Null(savedRec);

            // do this to make clear up code pass
            note.Id = orgId;
        }
Ejemplo n.º 26
0
        public void Can_Avoid_Duplicated_Parse_For_Valid_Note_Xml()
        {
            // Arrange
            var xmlDoc = XDocument.Parse($"<?xml version=\"1.0\" encoding=\"utf-16\" ?><Note xmlns=\"{CoreConstants.DefaultNoteNamespace}\"><Content>Test content</Content></Note>");

            var note = new HmmNote
            {
                Author  = _user,
                Subject = "Testing note",
                Content = $"<Note xmlns=\"{CoreConstants.DefaultNoteNamespace}\"><Content>Test content</Content></Note>"
            };

            // Act
            var newNote = _noteSerializer.GetNote(note);

            // Assert
            Assert.True(_noteSerializer.ProcessResult.Success);
            Assert.NotNull(newNote);
            Assert.Equal("Testing note", newNote.Subject);
            Assert.Equal(newNote.Content, xmlDoc.ToString(SaveOptions.DisableFormatting));
            Assert.Equal(newNote.CreateDate, newNote.LastModifiedDate);
        }
Ejemplo n.º 27
0
        public void Can_Search_Note_By_Id()
        {
            // Arrange
            var note = new HmmNote
            {
                Author  = _user,
                Subject = "Testing note",
                Content = "Test content"
            };

            CurrentTime = new DateTime(2021, 4, 4, 8, 15, 0);
            var newNote = _manager.Create(note);

            // Act
            var savedNote = _manager.GetNoteById(newNote.Id);

            // Assert
            Assert.True(_manager.ProcessResult.Success);
            Assert.NotNull(savedNote);
            Assert.Equal(savedNote.Subject, note.Subject);
            Assert.False(note.IsDeleted);
        }
Ejemplo n.º 28
0
        public void Cannot_Get_Deleted_Note()
        {
            // Arrange
            var note = new HmmNote
            {
                Author  = _user,
                Subject = "Testing note",
                Content = "Test content"
            };

            CurrentTime = new DateTime(2021, 4, 4, 8, 15, 0);
            var newNote = _manager.Create(note);

            // Act
            var result     = _manager.Delete(newNote.Id);
            var deleteNote = _manager.GetNoteById(newNote.Id);

            // Assert
            Assert.True(result);
            Assert.True(_manager.ProcessResult.Success);
            Assert.Null(deleteNote);
        }
Ejemplo n.º 29
0
        public override GasDiscount GetEntity(HmmNote note)
        {
            var(discountRoot, ns) = GetEntityRoot(note, AutomobileConstant.GasDiscountRecordSubject);
            if (discountRoot == null)
            {
                return(null);
            }
            _ = bool.TryParse(discountRoot.Element(ns + "IsActive")?.Value, out var isActive);
            _ = Enum.TryParse <GasDiscountType>(discountRoot.Element(ns + "DiscountType")?.Value, out var discType);
            var discount = new GasDiscount
            {
                Id           = note.Id,
                Program      = discountRoot.Element(ns + "Program")?.Value,
                Amount       = discountRoot.Element(ns + "Amount")?.GetMoney(),
                DiscountType = discType,
                IsActive     = isActive,
                Comment      = discountRoot.Element(ns + "Comment")?.Value,
                AuthorId     = note.Author.Id
            };

            return(discount);
        }
Ejemplo n.º 30
0
        public void Can_Update_NoteCatalog_To_Catalog_With_Invalid_Id_DefaultCatalog_Applied()
        {
            // Arrange - none exists catalog
            var catalog = new NoteCatalog
            {
                Id          = -1,
                Name        = "Gas Log",
                Description = "Testing catalog"
            };

            var initialCatalog = CatalogRepository.GetEntities().FirstOrDefault(cat => !cat.IsDefault);
            var xmlDoc         = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author           = _author,
                Catalog          = initialCatalog,
                Description      = "testing note",
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Subject          = "testing note is here",
                Content          = xmlDoc.InnerXml
            };

            NoteRepository.Add(note);
            Assert.True(NoteRepository.ProcessMessage.Success);

            note.Catalog = catalog;

            // Act
            var savedRec = NoteRepository.Update(note);

            // Assert
            Assert.True(NoteRepository.ProcessMessage.Success);
            Assert.NotNull(savedRec);
            Assert.NotNull(savedRec.Catalog);
            Assert.Equal("DefaultNoteCatalog", savedRec.Catalog.Name);
        }