public void Constructor_DefaultItem_ExpectedResult_CorrectId()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();
                _snapBoxController = new SnapBoxController(_stubContext);

                Assert.That(_stubContext.SnapBoxItems.ToList()[0].SnapBoxId, Is.EqualTo("000"));
            }
        }
        public void Constructor_NullContext_ExpectedResult_ExceptionThrown()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                Assert.That(() => _snapBoxController = new SnapBoxController(null),
                            Throws.Exception.TypeOf <NullReferenceException>());
            }
        }
        public void Constructor_DefaultItemCreated_ExpectedResult_True()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();
                _snapBoxController = new SnapBoxController(_stubContext);

                Assert.That(_stubContext.SnapBoxItems.Any(), Is.EqualTo(true));
            }
        }
        public void GetAll_ZeroItemsInDatabase_ExpectedResult_NoContentResult()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);
                _snapBoxController.Delete(1);

                Assert.That(() => _snapBoxController.GetAll(), Throws.Exception.TypeOf <NoItemsInDatabaseException>());
            }
        }
        public void Delete_OneItemDeleted_ExpectedResult_NoContentResult()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);

                IActionResult result = _snapBoxController.Delete(1);

                Assert.IsInstanceOf <NoContentResult>(result);
            }
        }
        public void Create_ValidItemGiven_ExpectedResult_CreatedAtRoute()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);

                IActionResult result = _snapBoxController.Create(_stubSnapBoxItem1);

                Assert.IsInstanceOf <CreatedAtRouteResult>(result);
            }
        }
        public void Create_BadItem_ExpectedResult_BadRequest()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);

                IActionResult result = _snapBoxController.Create(null);

                Assert.IsInstanceOf <BadRequestResult>(result);
            }
        }
        public void GetById_GivenId_ExpectedResult_ObjectResult()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);
                _snapBoxController.Create(_stubSnapBoxItem1);

                IActionResult result = _snapBoxController.GetById(2);

                Assert.IsInstanceOf <ObjectResult>(result);
            }
        }
        public void GetAll_ThreeItemsCreated_ExpectedResult_Count3()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);
                _snapBoxController.Create(_stubSnapBoxItem1);
                _snapBoxController.Create(_stubSnapBoxItem2);

                var lst = _snapBoxController.GetAll();

                Assert.That(lst.ToList().Count, Is.EqualTo(3));
            }
        }
        public void Create_PowerlevelNull_ExpectedResult_BadRequest()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);

                _stubSnapBoxItem1.PowerLevel = null;

                IActionResult result = _snapBoxController.Create(_stubSnapBoxItem1);

                Assert.IsInstanceOf <BadRequestObjectResult>(result, "Powerlevel null");
            }
        }
        public void Create_MailReceived_ReceiverMailNull_ExpectedResult_BadRequest()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);

                _stubSnapBoxItem1.MailReceived  = true;
                _stubSnapBoxItem1.ReceiverEmail = null;

                IActionResult result = _snapBoxController.Create(_stubSnapBoxItem1);

                Assert.IsInstanceOf <BadRequestObjectResult>(result, "No ReceiverEmail specified");
            }
        }
        public void GetById_SpecificAttribute_ExpectedResult_True()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);
                _snapBoxController.Create(_stubSnapBoxItem1);

                var result = _snapBoxController.GetById(2) as ObjectResult;
                Debug.Assert(result != null, nameof(result) + " != null");
                var model = result.Value as SnapBoxItem;

                Debug.Assert(model != null, nameof(model) + " != null");
                Assert.That(model.SnapBoxId, Is.EqualTo("007"));
            }
        }
        public void Delete_SeveralItemsDeleted_ExpectedResult_NonDeletedItemsStillExists()
        {
            using (_stubContext = new FwpsDbContext(_options))
            {
                _stubContext.Database.EnsureCreated();

                _snapBoxController = new SnapBoxController(_stubContext);
                _snapBoxController.Create(_stubSnapBoxItem1);
                _snapBoxController.Create(_stubSnapBoxItem2);

                _snapBoxController.Delete(1);
                _snapBoxController.Delete(3);

                var lst = _snapBoxController.GetAll().ToList();

                Assert.That(lst.Count, Is.EqualTo(1));
            }
        }