Example #1
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);
        }
Example #2
0
        public static NoteCatalog Clone(this NoteCatalog source, NoteCatalog targetCatalog = null)
        {
            if (source == null)
            {
                return(null);
            }

            if (targetCatalog == null)
            {
                var target = new NoteCatalog
                {
                    Id        = source.Id,
                    Name      = source.Name,
                    Subsystem = source.Subsystem,
                    Render    = source.Render.Clone(),
                    Schema    = source.Schema
                };
                return(target);
            }

            targetCatalog.Id        = source.Id;
            targetCatalog.Name      = source.Name;
            targetCatalog.Subsystem = source.Subsystem;
            targetCatalog.Render    = source.Render.Clone();
            targetCatalog.Schema    = source.Schema;

            return(targetCatalog);
        }
Example #3
0
        public void New_Add_Catalog_Can_Reference_Exists_Render()
        {
            // Arrange
            var render = _renderMan.GetEntities().FirstOrDefault();

            Assert.NotNull(render);
            var oldRenders = _renderMan.GetEntities().Count();
            var catalog    = new NoteCatalog
            {
                Name   = "Test Catalog",
                Render = render,
                Schema = "test schema"
            };

            // Act
            var newCatalog = _manager.Create(catalog);
            var renders    = _renderMan.GetEntities().Count();

            // Assert
            Assert.True(_manager.ProcessResult.Success);
            Assert.NotNull(newCatalog);
            Assert.Equal(oldRenders, renders);
            Assert.True(newCatalog.Id >= 1, "newNote.Id >=1");
            Assert.Equal("Test Catalog", newCatalog.Name);
        }
Example #4
0
        public NoteCatalog Update(NoteCatalog catalog)
        {
            if (catalog == null || !_validator.IsValidEntity(catalog, ProcessResult))
            {
                return(null);
            }

            // check if note render exists in data source
            if (_lookupRepo.GetEntity <NoteRender>(catalog.Render.Id) == null)
            {
                ProcessResult.AddErrorMessage($"Cannot update catalog: {catalog.Name}, because note render does not exists in data source");
                return(null);
            }
            // update catalog record
            var savedCatalog = _dataSource.GetEntity(catalog.Id);

            if (savedCatalog == null)
            {
                ProcessResult.AddErrorMessage($"Cannot update catalog: {catalog.Name}, because system cannot find it in data source");
                return(null);
            }
            var updatedCatalog = _dataSource.Update(catalog);

            if (updatedCatalog == null)
            {
                ProcessResult.PropagandaResult(_dataSource.ProcessMessage);
            }

            return(updatedCatalog);
        }
Example #5
0
        public void CanNot_Add_Already_Existed_NoteCatalog_To_DataSource()
        {
            // Arrange
            CatalogRepository.Add(new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note",
            });

            var cat = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = false,
                Description = "testing note",
            };

            // Act
            var savedRec = CatalogRepository.Add(cat);

            // Assert
            Assert.Null(savedRec);
            Assert.True(cat.Id <= 0, "cat.Id <=0");
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Example #6
0
        public void Can_Update_Catalog()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name   = "Test Catalog",
                Render = _render,
                Schema = "test schema"
            };

            _manager.Create(catalog);
            var savedCatalog = _manager.GetEntities().FirstOrDefault(c => c.Id == 1);

            Assert.NotNull(savedCatalog);

            // Act
            savedCatalog.Schema      = "changed test schema";
            savedCatalog.Render.Name = "Updated render name";
            var updatedCatalog = _manager.Update(savedCatalog);

            // Assert
            Assert.True(_manager.ProcessResult.Success);
            Assert.NotNull(updatedCatalog);
            Assert.Equal("changed test schema", updatedCatalog.Schema);
            Assert.Equal("Updated render name", savedCatalog.Render.Name);
            Assert.NotNull(updatedCatalog.Render);
        }
Example #7
0
        public void Cannot_Update_Catalog_With_Duplicated_Name()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };

            CatalogRepository.Add(catalog);

            var catalog2 = new NoteCatalog
            {
                Name        = "GasLog2",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = false,
                Description = "testing note2"
            };

            CatalogRepository.Add(catalog2);

            catalog.Name = catalog2.Name;

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

            // Assert
            Assert.Null(result);
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Example #8
0
        public void Can_Update_Catalog()
        {
            // Arrange - update name
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };

            CatalogRepository.Add(catalog);

            catalog.Name = "GasLog2";

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

            // Assert
            Assert.NotNull(result);
            Assert.Equal("GasLog2", result.Name);

            // Arrange - update description
            catalog.Description = "new testing note";

            // Act
            result = CatalogRepository.Update(catalog);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("new testing note", result.Description);
        }
Example #9
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);
        }
Example #10
0
        public void Cannot_Delete_NonExists_Catalog_From_DataSource()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };

            CatalogRepository.Add(catalog);

            var catalog2 = new NoteCatalog
            {
                Name        = "GasLog2",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = false,
                Description = "testing note"
            };

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

            // Assert
            Assert.False(result);
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Example #11
0
        public void NoteCatalog_Must_Has_Valid_Schema_Length(int schemaLen, bool expected)
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name   = "Test name",
                Render = new NoteRender
                {
                    Name      = "Test Render",
                    Namespace = "Test NameSpace"
                },
                Schema = GetRandomString(schemaLen)
            };

            // Act

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

            // Assert
            Assert.Equal(expected, result);
            if (!expected)
            {
                Assert.NotEmpty(processResult.MessageList[0].Message);
            }
        }
Example #12
0
        public void Cannot_Delete_NoteRender_With_CatalogAssociated()
        {
            // Arrange
            var render = new NoteRender
            {
                Name        = "DefaultRender",
                Namespace   = "NameSpace",
                IsDefault   = true,
                Description = "Description"
            };
            var savedRender = RenderRepository.Add(render);
            var catalog     = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = savedRender,
                Schema      = "Scheme",
                IsDefault   = true,
                Description = "testing Catalog"
            };

            CatalogRepository.Add(catalog);

            // Act
            var result = RenderRepository.Delete(render);

            // Assert
            Assert.False(result, "Error: deleted render with catalog attached to it");
            Assert.False(RenderRepository.ProcessMessage.Success);
            Assert.Single(RenderRepository.ProcessMessage.MessageList);
        }
Example #13
0
 private void SetupTestEnv()
 {
     InsertSeedRecords();
     _validator = new NoteValidator(NoteRepository);
     _author    = AuthorRepository.GetEntities().FirstOrDefault();
     _catalog   = CatalogRepository.GetEntities().FirstOrDefault();
     Assert.NotNull(_author);
     Assert.NotNull(_catalog);
 }
        private void SetupTestEnv()
        {
            InsertSeedRecords();
            _user = LookupRepo.GetEntities <Author>().FirstOrDefault();
            var schemaStr = File.ReadAllText("NotebaseSchema.xsd");
            var catalog   = new NoteCatalog {
                Schema = schemaStr
            };

            _noteSerializer = new TestDefaultXmlNoteSerializer(new NullLogger <HmmNote>(), catalog);
        }
Example #15
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);
        }
Example #16
0
        public void Can_Search_Catalog_By_Id()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name   = "Test Catalog",
                Render = _render,
                Schema = "test schema"
            };
            var newCatalog = _manager.Create(catalog);

            // Act
            var savedNote = _manager.GetEntities().FirstOrDefault(c => c.Id == newCatalog.Id);

            // Assert
            Assert.True(_manager.ProcessResult.Success);
            Assert.NotNull(savedNote);
            Assert.Equal(savedNote.Name, catalog.Name);
        }
Example #17
0
        public void Cannot_Update_Catalog_With_Invalid_Render()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name   = "Test Catalog",
                Render = _render,
                Schema = "test schema"
            };
            var savedCatalog = _manager.Create(catalog);

            // Act
            savedCatalog.Render = new NoteRender();
            var updatedCatalog = _manager.Update(savedCatalog);

            // Assert
            Assert.False(_manager.ProcessResult.Success);
            Assert.Null(updatedCatalog);
        }
Example #18
0
        public void Can_Add_NoteCatalog_To_DataSource()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                Description = "testing note",
            };

            // Act
            var savedRec = CatalogRepository.Add(catalog);

            // Assert
            Assert.NotNull(savedRec);
            Assert.True(savedRec.Id > 0, "savedRec.Id > 0");
            Assert.True(catalog.Id == savedRec.Id, "cat.Id == savedRec.Id");
            Assert.True(CatalogRepository.ProcessMessage.Success);
        }
Example #19
0
        public void Cannot_Update_Invalid_Catalog()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name   = "Test Catalog",
                Render = _render,
                Schema = "test schema"
            };
            var savedCatalog = _manager.Create(catalog);

            _testValidator.GetInvalidResult = true;

            // Act
            savedCatalog.Name = "updated test catalog";
            var updatedCatalog = _manager.Update(savedCatalog);

            // Assert
            Assert.False(_manager.ProcessResult.Success);
            Assert.Null(updatedCatalog);
        }
Example #20
0
        public NoteCatalog Create(NoteCatalog catalog)
        {
            if (catalog == null || !_validator.IsValidEntity(catalog, ProcessResult))
            {
                return(null);
            }

            try
            {
                var addedCatalog = _dataSource.Add(catalog);
                if (addedCatalog == null)
                {
                    ProcessResult.PropagandaResult(_dataSource.ProcessMessage);
                }
                return(addedCatalog);
            }
            catch (Exception ex)
            {
                ProcessResult.WrapException(ex);
                return(null);
            }
        }
Example #21
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);
        }
Example #22
0
        public void Cannot_Update_Not_Exists_Catalog()
        {
            // Arrange - no id
            var render = _renderMan.GetEntities().FirstOrDefault();

            Assert.NotNull(render);
            var catalog = new NoteCatalog
            {
                Name   = "Test Catalog",
                Render = render,
                Schema = "test schema"
            };

            // Act
            var updatedCatalog = _manager.Update(catalog);

            // Assert
            Assert.False(_manager.ProcessResult.Success);
            Assert.Null(updatedCatalog);

            // Arrange - id does not exists
            _manager.ProcessResult.Rest();
            catalog = new NoteCatalog
            {
                Id     = 100,
                Name   = "Test Catalog",
                Render = render,
                Schema = "test schema"
            };

            // Act
            updatedCatalog = _manager.Update(catalog);

            // Assert
            Assert.False(_manager.ProcessResult.Success);
            Assert.Null(updatedCatalog);
        }
Example #23
0
        public void NoteCatalog_Must_Has_Valid_Render_Length()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name   = "Test name",
                Render = new NoteRender
                {
                    Name      = "Test Render",
                    Namespace = "Test NameSpace"
                },
                Schema = "Test schema"
            };

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

            // Assert
            Assert.True(result);

            // Arrange
            catalog = new NoteCatalog
            {
                Name   = "Test name",
                Schema = "Test schema"
            };

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

            // Assert
            Assert.False(result);
            Assert.NotEmpty(processResult.MessageList[0].Message);
        }
 public TestDefaultXmlNoteSerializer(ILogger <HmmNote> logger, NoteCatalog catalog) : base(logger)
 {
     _catalog = catalog;
 }
Example #25
0
 //Action
 public void RemoveAt()
 {
     NoteCatalog.RemoveAt(SelectedIndex);
 }
Example #26
0
 //LAv en Update metode af typen Action
 // og kald en metode i NoteCatalog som skal opdatere en note
 public void Update()
 {
     NoteCatalog.Update(SelectedIndex, SelectedNote);
 }
Example #27
0
 public void Add()
 {
     NoteCatalog.Add(SelectedNote);
     SelectedNote = null;
 }
Example #28
0
 public NoteRepositoryTests()
 {
     SetupTestingEnv();
     _author  = AuthorRepository.GetEntities().FirstOrDefault();
     _catalog = CatalogRepository.GetEntities().FirstOrDefault(cat => cat.IsDefault);
 }