Esempio n. 1
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);
        }
Esempio n. 2
0
        protected TP PropertyChecking <TP>(TP property) where TP : HasDefaultEntity
        {
            var defaultNeeded = false;

            if (property == null)
            {
                defaultNeeded = true;
            }
            else if (property.Id <= 0)
            {
                defaultNeeded = true;
            }
            else if (LookupRepo.GetEntity <TP>(property.Id) == null)
            {
                defaultNeeded = true;
            }

            if (!defaultNeeded)
            {
                return(property);
            }

            var defaultProp = LookupRepo.GetEntities <TP>(p => p.IsDefault).FirstOrDefault();

            return(defaultProp);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 private void SetupTestEnv()
 {
     InsertSeedRecords();
     _user      = LookupRepo.GetEntities <Author>().FirstOrDefault();
     _validator = new NoteValidator(NoteRepository);
     _manager   = new HmmNoteManager(NoteRepository, _validator, DateProvider);
 }
Esempio n. 5
0
        private IApplication GetApplication()
        {
            var user   = LookupRepo.GetEntities <Author>().FirstOrDefault();
            var system = new Subsystem
            {
                DefaultAuthor = user,
            };

            var fakeApplication = new Mock <IApplication>();

            fakeApplication.Setup(app => app.GetApplication(LookupRepo)).Returns(system);
            fakeApplication.Setup(app => app.GetCatalog(It.IsAny <NoteCatalogType>(), It.IsAny <IEntityLookup>())).Returns((NoteCatalogType type, IEntityLookup lookupRepo) =>
            {
                NoteCatalog catalog;
                switch (type)
                {
                case NoteCatalogType.Automobile:
                    catalog = LookupRepo.GetEntities <NoteCatalog>()
                              .FirstOrDefault(c => c.Name == AutomobileConstant.AutoMobileInfoCatalogName);
                    if (catalog != null)
                    {
                        var schemaStr  = File.ReadAllText("Automobile.xsd");
                        catalog.Schema = schemaStr;
                    }
                    break;

                case NoteCatalogType.GasDiscount:
                    catalog = LookupRepo.GetEntities <NoteCatalog>()
                              .FirstOrDefault(c => c.Name == AutomobileConstant.GasDiscountCatalogName);
                    if (catalog != null)
                    {
                        var schemaStr  = File.ReadAllText("Discount.xsd");
                        catalog.Schema = schemaStr;
                    }
                    break;

                case NoteCatalogType.GasLog:
                    catalog = LookupRepo.GetEntities <NoteCatalog>()
                              .FirstOrDefault(c => c.Name == AutomobileConstant.GasLogCatalogName);
                    if (catalog != null)
                    {
                        var schemaStr  = File.ReadAllText("GasLog.xsd");
                        catalog.Schema = schemaStr;
                    }
                    break;

                default:
                    catalog = null;
                    break;
                }

                return(catalog);
            });

            return(fakeApplication.Object);
        }
        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);
        }
Esempio n. 7
0
        public void Can_Update_Subsystem()
        {
            // Arrange
            Assert.NotNull(_author);
            var sys = new Subsystem
            {
                Name          = "Test Subsystem",
                DefaultAuthor = _author,
                Description   = "Default Subsystem",
                NoteCatalogs  = new List <NoteCatalog>
                {
                    new()
                    {
                        Name   = "Test Catalog1",
                        Schema = "Test Catalog1 Schema",
                        Render = new NoteRender
                        {
                            Name        = "Test Catalog1 Render",
                            Namespace   = "Hmm.Render",
                            Description = "This is description of test catalog1 render"
                        }
                    },
                    new ()
                    {
                        Name   = "Test Catalog2",
                        Schema = "Test Catalog2 Schema",
                        Render = new NoteRender
                        {
                            Name        = "Test Catalog2 Render",
                            Namespace   = "Hmm.Render",
                            Description = "This is description of test catalog2 render"
                        }
                    }
                }
            };
            var newSys   = SubsystemRepository.Add(sys);
            var savedSys = LookupRepo.GetEntities <Subsystem>().FirstOrDefault(s => s.Id == newSys.Id);

            Assert.NotNull(savedSys);

            // Act
            savedSys.Description = "changed default Subsystem";
            var firstCatalog = savedSys.NoteCatalogs.First();

            Assert.NotNull(firstCatalog);
            firstCatalog.Name        = "Updated Test Catalog1";
            firstCatalog.Render.Name = "Update Test Catalog1 Render Name";
            var updatedSys = SubsystemRepository.Update(savedSys);

            // Assert
            Assert.NotNull(updatedSys);
            Assert.Equal("changed default Subsystem", updatedSys.Description);
            Assert.True(SubsystemRepository.ProcessMessage.Success);
        }
Esempio n. 8
0
        private void SetupDevEnv()
        {
            InsertSeedRecords();
            var catalog = LookupRepo.GetEntities <NoteCatalog>()
                          .FirstOrDefault(c => c.Name == AutomobileConstant.GasDiscountCatalogName);

            Assert.NotNull(catalog);
            var noteSerializer = new GasDiscountXmlNoteSerializer(Application, new NullLogger <GasDiscount>(), LookupRepo);
            var noteManager    = new HmmNoteManager(NoteRepository, new NoteValidator(NoteRepository), DateProvider);

            _manager  = new DiscountManager(noteSerializer, new GasDiscountValidator(LookupRepo), noteManager, LookupRepo);
            _authorId = ApplicationRegister.DefaultAuthor.Id;
        }
Esempio n. 9
0
        private void SetupDevEnv()
        {
            InsertSeedRecords();

            // add testing note catalog
            var catalog = LookupRepo.GetEntities <NoteCatalog>()
                          .FirstOrDefault(c => c.Name == AutomobileConstant.AutoMobileInfoCatalogName);

            Assert.NotNull(catalog);
            var noteSerializer = new AutomobileXmlNoteSerializer(Application, new NullLogger <AutomobileInfo>(), LookupRepo);
            var noteManager    = new HmmNoteManager(NoteRepository, new NoteValidator(NoteRepository), DateProvider);

            _manager = new AutomobileManager(noteSerializer, new AutomobileValidator(LookupRepo), noteManager, LookupRepo);
        }
Esempio n. 10
0
        public void Can_Check_Author_Exists(string authorId, bool expected)
        {
            // Arrange
            var id = authorId;

            if (authorId == "FirstID")
            {
                id = LookupRepo.GetEntities <Author>().FirstOrDefault()?.Id.ToString();
            }

            // Act
            var result = _authorManager.AuthorExists(id);

            // Assert
            Assert.Equal(result, expected);
        }
Esempio n. 11
0
        public void Dispose()
        {
            if (_dbContext is DbContext context)
            {
                context.Reset();
            }

            var systems = LookupRepo.GetEntities <Subsystem>().ToList();

            foreach (var sys in systems)
            {
                SubsystemRepository.Delete(sys);
            }
            var notes = LookupRepo.GetEntities <HmmNote>().ToList();

            foreach (var note in notes)
            {
                NoteRepository.Delete(note);
            }

            var catalogs = LookupRepo.GetEntities <NoteCatalog>().ToList();

            foreach (var catalog in catalogs)
            {
                CatalogRepository.Delete(catalog);
            }

            var renders = LookupRepo.GetEntities <NoteRender>().ToList();

            foreach (var render in renders)
            {
                RenderRepository.Delete(render);
            }

            var authors = LookupRepo.GetEntities <Author>().ToList();

            foreach (var author in authors)
            {
                AuthorRepository.Delete(author);
            }

            if (_dbContext is DbContext newContext)
            {
                newContext.Reset();
            }
            GC.SuppressFinalize(this);
        }
Esempio n. 12
0
 public PageList <NoteRender> GetEntities(Expression <Func <NoteRender, bool> > query = null, ResourceCollectionParameters resourceCollectionParameters = null)
 {
     return(LookupRepo.GetEntities(query, resourceCollectionParameters));
 }