Ejemplo n.º 1
0
        public void RemoveDiary()
        {
            //--Arrange
            var   random   = new Random();
            Diary expected = new Diary
            {
                Id       = random.Next(1_000_000, 2_000_000),
                Name     = "DeleteDiary",
                Location = "DeleteLocation",

                CreatedOn = new DateTime(2020, 8, 8),
            };
            var dbContextFactory = new AtwDbContextFactory();
            var dbContext        = dbContextFactory.CreateDbContext(new string[0]);

            var diaryRepository = new DiaryRepository(dbContext);

            //--Act
            diaryRepository.Add(expected);
            diaryRepository.SaveChanges();
            diaryRepository.Remove(expected);
            diaryRepository.SaveChanges();
            var actual = diaryRepository.GetById(expected.Id);

            //--Assert
            Assert.IsNull(actual);

            dbContext.Dispose();
        }
Ejemplo n.º 2
0
        public void AddDiary()
        {
            //--Arrange
            var   random   = new Random();
            Diary expected = new Diary
            {
                Id       = random.Next(1_000_000, 2_000_000),
                Name     = "AddDiary",
                Location = "Location3",

                CreatedOn = new DateTime(2020, 5, 5),
            };

            var dbContextFactory = new AtwDbContextFactory();
            var dbContext        = dbContextFactory.CreateDbContext(new string[0]);

            var diaryRepository = new DiaryRepository(dbContext);

            //--Act

            diaryRepository.Add(expected);
            diaryRepository.SaveChanges();
            var actual = diaryRepository.GetById(expected.Id);


            //--Assert

            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Location, actual.Location);

            Assert.AreEqual(expected.CreatedOn, actual.CreatedOn);

            dbContext.Dispose();
        }
Ejemplo n.º 3
0
        public void GetDiary()
        {
            //--Arrange
            Diary expected = new Diary
            {
                Id       = 1,
                Name     = "Test",
                Location = "TestLocation",

                CreatedOn = new DateTime(2020, 1, 1),
            };

            var dbContextFactory = new AtwDbContextFactory();
            var dbContext        = dbContextFactory.CreateDbContext(new string[0]);

            var diaryRepository = new DiaryRepository(dbContext);


            //--Act
            var actual = diaryRepository.GetById(1);

            //--Assert
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Location, actual.Location);

            Assert.AreEqual(expected.CreatedOn, actual.CreatedOn);

            dbContext.Dispose();
        }
Ejemplo n.º 4
0
        public void AddAtwImageTest()
        {
            //-- Arrange
            var      random      = new Random();
            var      projectPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            AtwImage expected    = new AtwImage
            {
                Id        = random.Next(1_000_000, 2_000_000),
                Content   = File.ReadAllBytes(Path.Combine(projectPath, "DataSeed/black-panther-background.jpg")),
                CreatedOn = new DateTime(2020, 2, 2)
            };

            var dbContextFactory = new AtwDbContextFactory();
            var dbContext        = dbContextFactory.CreateDbContext(new string[0]);

            var atwImageRepository = new AtwImageRepository(dbContext);

            //-- Act
            atwImageRepository.Add(expected);
            atwImageRepository.SaveChanges();
            var actual = atwImageRepository.GetById(expected.Id);



            //--Assert
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.Content, actual.Content);
            Assert.AreEqual(expected.CreatedOn, actual.CreatedOn);


            dbContext.Dispose();
        }
    }
Ejemplo n.º 5
0
        public void AddChapterTest()
        {
            //-- Arrange
            var     random   = new Random();
            Chapter expected = new Chapter
            {
                Id        = random.Next(1_000_000, 2_000_000),
                DiaryId   = 1,
                Name      = "TestChapter",
                Location  = "Narnia",
                Date      = new DateTime(2020, 3, 3),
                Content   = "Test Content",
                CreatedOn = new DateTime(2020, 9, 9)
            };

            var dbContextFactory = new AtwDbContextFactory();
            var dbContext        = dbContextFactory.CreateDbContext(new string[0]);

            var chapterRepository = new ChapterRepository(dbContext);

            //-- Act
            chapterRepository.Add(expected);
            chapterRepository.SaveChanges();
            var actual = chapterRepository.GetById(expected.Id);



            //--Assert
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.DiaryId, actual.DiaryId);
            Assert.AreEqual(expected.Name, actual.Name);
            Assert.AreEqual(expected.Location, actual.Location);
            Assert.AreEqual(expected.Date, actual.Date);
            Assert.AreEqual(expected.Content, actual.Content);
            Assert.AreEqual(expected.CreatedOn, actual.CreatedOn);

            dbContext.Dispose();
        }
Ejemplo n.º 6
0
        public void Should_Fail_When_AddingAChapterWithNegativeDiaryId()
        {
            var dbContextFactory = new AtwDbContextFactory();
            var dbContext        = dbContextFactory.CreateDbContext(new string[0]);

            try
            {
                //-- Arrange
                var     random   = new Random();
                Chapter expected = new Chapter
                {
                    Id        = random.Next(1_000_000, 2_000_000),
                    DiaryId   = -1,
                    Name      = "TestChapter",
                    Location  = "Narnia",
                    Date      = new DateTime(2020, 3, 3),
                    Content   = "Test Content",
                    CreatedOn = new DateTime(2020, 9, 9)
                };



                var chapterRepository = new ChapterRepository(dbContext);

                //-- Act
                chapterRepository.Add(expected);
                chapterRepository.SaveChanges();
            }

            finally
            {
                dbContext.Dispose();
            }


            //--Assert
        }