Пример #1
0
        public void CreateCreatesCorrectly()
        {
            // setup
            var bookType = new MaterialType {
                Type = "Book"
            };
            var programmingSubject = new MaterialSubject {
                SubjectName = "Programming"
            };
            var author = new Author {
                FirstName = "Nikola", LastName = "Velichkov"
            };
            var options = new DbContextOptionsBuilder <GTLContext>()
                          .UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var context = new GTLContext(options))
            {
                context.Add(bookType);
                context.Add(programmingSubject);
                context.Add(author);

                context.SaveChanges();
            }

            // action
            using (var context = new GTLContext(options))
            {
                var controller = ControllerFactory.CreateMaterialController(context);
                var material   = controller.Create(
                    _isbn,
                    _title,
                    _language,
                    _lendable,
                    _description,
                    bookType,
                    new List <MaterialSubject> {
                    programmingSubject
                },
                    new List <Author> {
                    author
                }
                    );
                // assertion

                Assert.That(material, Has
                            .Property(nameof(Material.Isbn)).EqualTo(_isbn).And
                            .Property(nameof(Material.Title)).EqualTo(_title).And
                            .Property(nameof(Material.Language)).EqualTo(_language).And
                            .Property(nameof(Material.Lendable)).EqualTo(_lendable).And
                            .Property(nameof(Material.Description)).EqualTo(_description).And
                            .Property(nameof(Material.Type)).And
                            .Property(nameof(Material.MaterialSubjects)).And
                            .Property(nameof(Material.MaterialAuthors)));
            }
        }
Пример #2
0
        // should be more tests with the same conditions for different properties of Material
        // (Isbn, Title, Language, Description, Lendable?)
        public void CreateThrowsAnArgumentNullExceptionOnNullOrEmptyTitle()
        {
            // setup
            var bookType = new MaterialType {
                Type = "Book"
            };
            var programmingSubject = new MaterialSubject {
                SubjectName = "Programming"
            };
            var author = new Author {
                FirstName = "Nikola", LastName = "Velichkov"
            };
            var options = new DbContextOptionsBuilder <GTLContext>()
                          .UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var context = new GTLContext(options))
            {
                context.Add(bookType);
                context.Add(programmingSubject);
                context.Add(author);

                context.SaveChanges();
            }

            // assertion
            using (var context = new GTLContext(options))
            {
                var controller = ControllerFactory.CreateMaterialController(context);
                Assert.Throws <ArgumentNullException>(() =>
                                                      controller.Create(
                                                          _isbn,
                                                          "",
                                                          _language,
                                                          _lendable,
                                                          _description,
                                                          bookType,
                                                          new List <MaterialSubject> {
                    programmingSubject
                },
                                                          new List <Author> {
                    author
                }
                                                          ));
            }
        }