Пример #1
0
        public void ToDataModel_WithoutIdAndWithoutBookId()
        {
            // Arrange
            var bookId = _fixture.Create <Guid>();
            var author = _fixture.Build <Author>()
                         .Without(p => p.Id)
                         .Without(p => p.BookId)
                         .Create();

            var expected = new AuthorDb
            {
                FirstName = author.FirstName,
                LastName  = author.LastName,
                BookId    = bookId
            };

            // Act
            var result = _target.ToDataModel(author, bookId);

            // Assert
            Assert.AreNotEqual(Guid.Empty, result.Id);

            expected.Id = result.Id;
            result.Should().BeEquivalentTo(expected);
        }
Пример #2
0
        /// <summary>
        /// Gets all author courses by author in repository.
        /// </summary>
        /// <param name="author"></param>
        /// <returns></returns>
        public async Task <IEnumerable <CourseDb> > GetByAuthorAsync(AuthorDb author)
        {
            var courses = await _videoDbContext.Authors.Where(c => c.AuthorId == author.AuthorId)?.SelectMany(c => c.AuthorCourses).ToListAsync();

            //var courses = await _videoDbContext.Tags.Where(c => c.TagId == tag.TagId)?.SelectMany(c => c.Courses).ToListAsync();
            return(courses.AsReadOnly());;
        }
Пример #3
0
 /// <summary>
 /// Remove author in repository.
 /// </summary>
 /// <param name="author"></param>
 /// <returns></returns>
 public async Task RemoveAsync(AuthorDb author)
 {
     if (author == null)
     {
         throw new ArgumentNullException("author");
     }
     _videoDbContext.Authors.Remove(author);
     await _videoDbContext.SaveChangesAsync().ConfigureAwait(false);
 }
Пример #4
0
 /// <summary>
 /// Update author.
 /// </summary>
 /// <param name="author"></param>
 /// <returns></returns>
 public async Task <AuthorDb> UpdateAsync(AuthorDb author)
 {
     if (author == null)
     {
         throw new ArgumentNullException("author");
     }
     _videoDbContext.Entry(author).State = EntityState.Modified;
     _videoDbContext.SaveChangesAsync().ConfigureAwait(false).GetAwaiter().GetResult();
     return(await Task.FromResult(author));
 }
Пример #5
0
 public Author ToDomainModel(AuthorDb author)
 {
     return(new Author
     {
         Id = author.Id,
         FirstName = author.FirstName,
         LastName = author.LastName,
         BookId = author.BookId
     });
 }
Пример #6
0
        //method to make GET requests and save author objects to author repository list
        private static async void CreateAuthorsList(AuthorDb all)
        {
            for (int i = 1; i < 3; i++)
            {
                Task <Page> page    = GetAuthorRequest("https://jsonmock.hackerrank.com/api/article_users/search?page=" + i);
                Page        apiPage = await page;

                foreach (var author in apiPage.data)
                {
                    all.allAuthors.Add(author);
                }
            }
        }
Пример #7
0
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //create instance of author repository list
            AuthorDb all = new AuthorDb();

            //make GET requests and save author objects to author repository list
            CreateAuthorsList(all);

            //create the connection between the UI and the library
            DISocket.PlugSocket();
            ILinqOperations operations = DISocket.Isocket;

            //run Form app
            Application.Run(new Form1(all, operations));
        }
Пример #8
0
        public void ToDataModel()
        {
            // Arrange
            var bookId = _fixture.Create <Guid>();
            var author = _fixture.Create <Author>();

            var expected = new AuthorDb
            {
                Id        = author.Id,
                FirstName = author.FirstName,
                LastName  = author.LastName,
                BookId    = author.BookId
            };

            // Act
            var result = _target.ToDataModel(author, bookId);

            // Assert
            result.Should().BeEquivalentTo(expected);
        }
Пример #9
0
 /// <summary>
 /// Create a new author in repository.
 /// </summary>
 /// <param name="author"></param>
 /// <returns></returns>
 public async Task <AuthorDb> AddAsync(AuthorDb author)
 {
     _videoDbContext.Authors.Add(author);
     _videoDbContext.SaveChangesAsync().ConfigureAwait(false).GetAwaiter().GetResult();
     return(await Task.FromResult(author));
 }
Пример #10
0
        public void InitMock()
        {
            _coursesDb = new List <CourseDb>()
            {
                new CourseDb()
                {
                    CourseId = "idCourse1", Name = "Course1", Price = 10, Date = DateTime.Now, Description = "Description1", Level = 1, Raiting = 5
                },
                new CourseDb()
                {
                    CourseId = "idCourse2", Name = "Course2", Price = 20, Date = DateTime.Now, Description = "Description2", Level = 2, Raiting = 4
                },
                new CourseDb()
                {
                    CourseId = "idCourse3", Name = "Course3", Price = 30, Date = DateTime.Now, Description = "Description3", Level = 2, Raiting = 3
                }
            };

            _coursesInfo = new List <CourseInfo>()
            {
                new CourseInfo()
                {
                    Name = "Course1", Price = 10, Description = "Description1", Duration = 15, Level = 1, Raiting = 5
                },
                new CourseInfo()
                {
                    Name = "Course2", Price = 20, Description = "Description2", Duration = 25, Level = 2, Raiting = 4
                },
                new CourseInfo()
                {
                    Name = "Course3", Price = 30, Description = "Description3", Duration = 35, Level = 2, Raiting = 3
                }
            };

            _autorsDb = new List <AuthorDb>()
            {
                new AuthorDb()
                {
                    AuthorId = "id1", Name = "name1", Lastname = "lastname1", Annotation = "Annotation1", Professions = "Professions1", AuthorCourses = _coursesDb
                },
                new AuthorDb()
                {
                    AuthorId = "id2", Name = "name2", Lastname = "lastname2", Annotation = "Annotation2", Professions = "Professions2"
                },
                new AuthorDb()
                {
                    AuthorId = "id3", Name = "name3", Lastname = "lastname3", Annotation = "Annotation3", Professions = "Professions3"
                }
            }.AsQueryable();

            _oneAuthorDb = new AuthorDb()
            {
                AuthorId = "id4", Name = "name4", Lastname = "lastname4", Annotation = "Annotation4", Professions = "Professions4"
            };

            _authorsInfo = new List <AuthorInfo>()
            {
                new AuthorInfo()
                {
                    Name = "name1", Lastname = "lastname1", Annotation = "Annotation1", Professions = "Professions1"
                },
                new AuthorInfo()
                {
                    Name = "name2", Lastname = "lastname2", Annotation = "Annotation2", Professions = "Professions2"
                },
                new AuthorInfo()
                {
                    Name = "name3", Lastname = "lastname3", Annotation = "Annotation3", Professions = "Professions3"
                }
            }.AsQueryable();

            _oneAuthorInfo = new AuthorInfo()
            {
                Name = "name4", Lastname = "lastname4", Annotation = "Annotation4", Professions = "Professions4"
            };

            _mockSet = new Mock <DbSet <AuthorDb> >();
            _mockSet.As <IQueryable <AuthorDb> >().Setup(m => m.Expression).Returns(_autorsDb.Expression);
            _mockSet.As <IQueryable <AuthorDb> >().Setup(m => m.ElementType).Returns(_autorsDb.ElementType);
            _mockSet.As <IQueryable <AuthorDb> >().Setup(m => m.GetEnumerator()).Returns(_autorsDb.GetEnumerator());
            _mockContext = new Mock <VideoDbContext>();
            _mockMapper  = new Mock <IMapper>();
        }
Пример #11
0
 //form constructor
 public Form1(AuthorDb all, ILinqOperations operations)
 {
     InitializeComponent();
     All       = all;
     Operation = operations;
 }
Пример #12
0
        protected override void Seed(BulbaCourses.Video.Data.DatabaseContext.VideoDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            #region Users
            var user1 = new UserDb()
            {
                UserId           = Guid.NewGuid().ToString(),
                Login            = "******",
                SubscriptionType = 1
            };
            var user2 = new UserDb()
            {
                UserId           = Guid.NewGuid().ToString(),
                Login            = "******",
                SubscriptionType = 1
            };
            context.Users.Add(user1);
            context.Users.Add(user2);
            #endregion

            #region Tags
            var tag1 = new TagDb()
            {
                TagId   = Guid.NewGuid().ToString(),
                Content = "C#"
            };
            List <TagDb> tagDbC = new List <TagDb>()
            {
                tag1
            };
            var tag2 = new TagDb()
            {
                TagId   = Guid.NewGuid().ToString(),
                Content = "ASP.Net"
            };
            List <TagDb> tagDbCSharp = new List <TagDb>()
            {
                tag1, tag2
            };
            var tag3 = new TagDb()
            {
                TagId   = Guid.NewGuid().ToString(),
                Content = "Java"
            };
            var tag4 = new TagDb()
            {
                TagId   = Guid.NewGuid().ToString(),
                Content = "Automated"
            };
            var tag5 = new TagDb()
            {
                TagId   = Guid.NewGuid().ToString(),
                Content = "Testing"
            };
            List <TagDb> tagDbJava = new List <TagDb>()
            {
                tag3, tag4, tag5
            };
            var tag6 = new TagDb()
            {
                TagId   = Guid.NewGuid().ToString(),
                Content = "Network"
            };
            var tag7 = new TagDb()
            {
                TagId   = Guid.NewGuid().ToString(),
                Content = "DHCP"
            };
            List <TagDb> tagDbNet = new List <TagDb>()
            {
                tag6, tag7
            };

            context.Tags.Add(tag1);
            context.Tags.Add(tag2);
            context.Tags.Add(tag3);
            context.Tags.Add(tag4);
            context.Tags.Add(tag5);
            context.Tags.Add(tag6);
            context.Tags.Add(tag7);
            #endregion

            #region Authors
            var author1 = new AuthorDb()
            {
                AuthorId   = Guid.NewGuid().ToString(),
                Name       = "Aleksandr",
                Lastname   = "Shaduro",
                Annotation = "Experienced Instructor with a demonstrated history of working in the higher education industry. " +
                             "Skilled in WEB Development, Agile Methodologies. Strong education professional graduated from Belarusian State University",
                Professions = "Chief Technical Officer at Artooba"
            };
            var author2 = new AuthorDb()
            {
                AuthorId   = Guid.NewGuid().ToString(),
                Name       = "Aleksandr",
                Lastname   = "Korablin",
                Annotation = "MCSD: MICROSOFT CERTIFIED SOLUTION DEVELOPER, ORACLE CERTIFIED ASSOCIATE, " +
                             "JAVA SE 7 PROGRAMMER, WINDOWS AZURE DEVELOPER, MICROSOFT CERTIFIED TRAINER",
                Professions = "MICROSOFT CERTIFIED SOLUTION DEVELOPER"
            };
            var author3 = new AuthorDb()
            {
                AuthorId    = Guid.NewGuid().ToString(),
                Name        = "Aleksandr",
                Lastname    = "Borovoy",
                Annotation  = "Local network, DHCP, DNS, NOD-32",
                Professions = "Local network"
            };
            context.Authors.Add(author1);
            context.Authors.Add(author2);
            context.Authors.Add(author3);
            #endregion

            #region Courses
            var course1 = new CourseDb()
            {
                CourseId    = Guid.NewGuid().ToString(),
                Name        = "ASP by Shaduro",
                Author      = author1,
                Level       = 1,
                Raiting     = 5,
                RateCount   = 20,
                Description = ".NET is a developer platform made up of tools, programming languages, and libraries for building many different types of applications." +
                              "ASP.NET extends the.NET developer platform with tools and libraries specifically for building web apps.",
                Date  = DateTime.Now,
                Price = 850,
                Tags  = tagDbCSharp
            };

            var course2 = new CourseDb()
            {
                CourseId    = Guid.NewGuid().ToString(),
                Name        = "Programming in C#",
                Author      = author1,
                Level       = 1,
                Raiting     = 4,
                RateCount   = 12,
                Description = "C#(Sharp) is an object-oriented programming language developed by Microsoft.",
                Date        = DateTime.Now,
                Price       = 50,
                Tags        = tagDbC
            };

            var course3 = new CourseDb()
            {
                CourseId    = Guid.NewGuid().ToString(),
                Name        = "Java for Automated Testing",
                Author      = author2,
                Level       = 1,
                Raiting     = 4,
                RateCount   = 10,
                Description = "Test automation, a formalized testing process, can automate repetitive but necessary tasks that would be difficult to do manually.",
                Date        = DateTime.Now,
                Price       = 70,
                Tags        = tagDbJava
            };

            var course4 = new CourseDb()
            {
                CourseId    = Guid.NewGuid().ToString(),
                Name        = "Local Network",
                Author      = author3,
                Level       = 1,
                Raiting     = 3,
                RateCount   = 6,
                Description = "A local area network (LAN) is a computer network that interconnects computers within a limited area.",
                Date        = DateTime.Now,
                Price       = 10,
                Tags        = tagDbNet
            };

            context.Courses.Add(course1);
            context.Courses.Add(course2);
            context.Courses.Add(course3);
            context.Courses.Add(course4);
            #endregion

            #region Videos
            var video1 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "validation",
                Url           = @"D:\TestCourses\ASP by Shaduro\1_video_validation.mp4",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 1,
                CourseId      = course1.CourseId
            };
            var video2 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "Refactiring & Security",
                Url           = @"D:\TestCourses\ASP by Shaduro\2_video_refactiring_&_security.mp4",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 2,
                CourseId      = course1.CourseId
            };
            var video3 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "Angular_Basic",
                Url           = @"D:\TestCourses\ASP by Shaduro\3_video_angular_basic.mp4",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 3,
                CourseId      = course1.CourseId
            };
            var video4 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "C# start part.1",
                Url           = @"D:\TestCourses\Programming in C#\1_1_x264.mp4",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 1,
                CourseId      = course2.CourseId
            };
            var video5 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "C# start part.1",
                Url           = @"D:\TestCourses\Programming in C#\1_2_x264.mp4",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 2,
                CourseId      = course2.CourseId
            };
            var video6 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "Java Fundamentals",
                Url           = @"D:\TestCourses\Java for Automated Testing\01_Java Fundamentals.wmv",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 1,
                CourseId      = course3.CourseId
            };
            var video7 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "Object Oriented Programming",
                Url           = @"D:\TestCourses\Java for Automated Testing\02_Object Oriented Programming.wmv",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 2,
                CourseId      = course3.CourseId
            };
            var video8 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "Numbers, strings, dates",
                Url           = @"D:\TestCourses\Java for Automated Testing\03_Numbers, strings, dates.avi",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 3,
                CourseId      = course3.CourseId
            };
            var video9 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "¬водный урок",
                Url           = @"D:\TestCourses\Ћокальна¤ компьютерна¤ сеть\”рок 1 Ч ¬водный урок.avi",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 1,
                CourseId      = course4.CourseId
            };
            var video10 = new VideoMaterialDb()
            {
                VideoId       = Guid.NewGuid().ToString(),
                Name          = "«акрыта¤ серверна¤ стойка",
                Url           = @"D:\TestCourses\Ћокальна¤ компьютерна¤ сеть\”рок 2 Ч ќбзор закрытой серверной стойки.avi",
                Created       = DateTime.Now,
                NumberOfViews = 1,
                Order         = 2,
                CourseId      = course4.CourseId
            };

            context.VideoMaterials.Add(video1);
            context.VideoMaterials.Add(video2);
            context.VideoMaterials.Add(video3);
            context.VideoMaterials.Add(video4);
            context.VideoMaterials.Add(video5);
            context.VideoMaterials.Add(video6);
            context.VideoMaterials.Add(video7);
            context.VideoMaterials.Add(video8);
            context.VideoMaterials.Add(video9);
            context.VideoMaterials.Add(video10);
            #endregion

            base.Seed(context);
        }