public void GetAll_ListOfItems_ExpectedResult_ReturnedView()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc = new LightController(_context, _hub);
                _lc.Create(_li);
                _lc.Create(_li2);

                Assert.That(_lc.GetAll(), Is.EqualTo(_context.LightItems.ToList()));
            }
        }
        public void GetAll_ThreeLightItems_ExpectedResult_3()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc = new LightController(_context, _hub);
                _lc.Create(_li);
                _lc.Create(_li2);

                var results = _lc.GetAll().ToList();

                Assert.That(results.Count, Is.EqualTo(3));
            }
        }
        public void Delete_SeveralDeletionsFromDatabase_ExpectedResult_NoItemsLeft()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc = new LightController(_context, _hub);
                _lc.Create(_li);
                _lc.Create(_li2);

                _lc.Delete(1);
                _lc.Delete(2);
                _lc.Delete(3);

                Assert.That(_lc.GetAll().ToList().Count, Is.EqualTo(0));
            }
        }
        public void Create_CreateTwoItems_ValidLightItems_ExpectedResult_CountEquals3()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();

                _lc = new LightController(_context, _hub);

                _lc.Create(_li);
                _lc.Create(_li2);

                List <LightItem> list = _context.LightItems.ToList();

                Assert.That(list.Count, Is.EqualTo(3));
            }
        }
        public void GetAll_ThreeLightItems_ExpectedResult_Command_on_What_What()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc = new LightController(_context, _hub);
                _lc.Create(_li);
                _lc.Create(_li2);

                var results = _lc.GetAll().ToList();

                Assert.That(results[0].Command, Is.EqualTo("on"));
                Assert.That(results[1].Command, Is.EqualTo("What"));
                Assert.That(results[2].Command, Is.EqualTo("When"));
            }
        }
        public void Next_ThreeLightItems_ExpectedResult_FirstItemOnly()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc = new LightController(_context, _hub);
                _lc.Create(_li);
                _lc.Create(_li2);

                var result = _lc.Next() as ObjectResult;
                var model  = result.Value as LightItem;

                Assert.That(model.Command, Is.EqualTo("on"));
                Assert.That(model.Command, Is.EqualTo("on"));
            }
        }
        public void Newest_ThreeLightItems_ExpectedResult_LastItemOnly()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc = new LightController(_context, _hub);
                _lc.Create(_li);
                _lc.Create(_li2);

                var result = _lc.Newest() as ObjectResult;
                Debug.Assert(result != null, nameof(result) + " != null");
                var model = result.Value as LightItem;

                Debug.Assert(model != null, nameof(model) + " != null");
                Assert.That(model.Command, Is.EqualTo("When"));
                Assert.That(model.Command, Is.EqualTo("When"));
            }
        }
        public void Create_CreateItem_NullItem_ExpectedResult_NoHubRequestRecieved()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();

                _lc = new LightController(_context, _hub);

                _lc.Create(null);

                _hub.Clients.All.DidNotReceive().InvokeAsync(Arg.Any <string>());
            }
        }
        public void GetById_IdNotExisting_ExpectedResult_NullReferenceException()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc         = new LightController(_context, _hub);
                _li.Command = "FirstItem";
                _lc.Create(_li);

                const long id = 3;

                var result = _lc.GetById(id) as ObjectResult;

                Assert.That(() => result.Value as LightItem, Throws.Exception.TypeOf <NullReferenceException>());
            }
        }
        public void Create_CreateItem_CorrectStringInputSecondArg_ExpectedResult_True()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();

                _lc = new LightController(_context, _hub);

                _lc.Create(_li);

                _hub.Clients.All.Received(1).InvokeAsync(
                    Arg.Any <string>(),
                    Arg.Is <string>(secondArg => secondArg == "MorningSun"),
                    Arg.Any <string>(),
                    Arg.Any <object>());
            }
        }
        public void GetById_IdExist_ExpectedResult_LightItemReturned()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();
                _lc         = new LightController(_context, _hub);
                _li.Command = "FirstItem";
                _lc.Create(_li);

                const long id = 2;

                var result = _lc.GetById(id) as ObjectResult;
                var model  = result?.Value as LightItem;

                Debug.Assert(model != null, nameof(model) + " != null");
                Assert.That(model.Id, Is.EqualTo(id));
            }
        }
        public void Create_CreateItem_CorrectObjectInputFourthArg_ExpectedResult_True()
        {
            using (_context = new FwpsDbContext(_options))
            {
                _context.Database.EnsureCreated();

                _lc = new LightController(_context, _hub);

                _li.Command = "ThirdArg";

                _lc.Create(_li);

                _hub.Clients.All.Received(1).InvokeAsync(
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Any <string>(),
                    Arg.Is <LightItem>(fourthArg => fourthArg == _li)
                    );
            }
        }
        public void Update_UpdateItem_ExpectedResult_CommandUpdated()
        {
            using (_context = new FwpsDbContext(_options))
            {
                long id = 2;
                _li.Id = id;

                _context.Database.EnsureCreated();

                _li2.Command = "SecondItem";
                _lc          = new LightController(_context, _hub);

                _lc.Create(_li2);

                _li.Command = "FirstItem";
                _lc.Update(id, _li);

                Assert.That(_context.LightItems.
                            ToList()[1].Command,
                            Is.EqualTo("FirstItem"));
            }
        }