Example #1
0
        public void Edit_Returns_CorrectParameterData()
        {
            var panelController = new PanelController();

            var key = new Key
            {
                Description = "TestDescription2",
                Name        = "TestName2",
                Illuminated = true,
                State       = KeyState.In,
                PersonID    = 0
            };

            panelController.Create(null, key);

            using (var context = new KeyContext())
            {
                key = context.Keys.FirstOrDefault(r => r.Name.Equals("TestName2"));
            }

            Assert.That(key != null, "No object returned");

            keys.Add(key.ID);

            key.Name        = "UpdatedName";
            key.Description = "UpdatedDescription";

            //Update existing key
            panelController.Edit(key.ID, key);

            Key      returnKey;
            KeyAudit returnKeyAudit;

            using (var context = new KeyContext())
            {
                returnKey      = context.Keys.FirstOrDefault(r => r.ID == key.ID);
                returnKeyAudit = context.KeyAudits.FirstOrDefault(r => r.ID == key.ID && r.AuditNote.Equals("UPDATED"));
            }

            Assert.That(returnKey != null, "No object returned");

            bool valuesMatch = key.Description == returnKey.Description;

            Assert.IsTrue(valuesMatch, "Description of return object did not match persisted object");

            valuesMatch = key.Illuminated == returnKey.Illuminated;
            Assert.IsTrue(valuesMatch, "Illuminated of return object did not match persisted object");

            valuesMatch = key.PersonID == returnKey.PersonID;
            Assert.IsTrue(valuesMatch, "PersonID of return object did not match persisted object");

            valuesMatch = key.State == returnKey.State;
            Assert.IsTrue(valuesMatch, "State of return object did not match persisted object");

            Assert.That(returnKeyAudit != null, "No audit object returned");

            valuesMatch = returnKeyAudit.AuditNote.Equals("UPDATED");
            Assert.IsTrue(valuesMatch, "No audit note was attached to audit record");

            valuesMatch = key.Description == returnKeyAudit.Description;
            Assert.IsTrue(valuesMatch, "Description of return audit object did not match object");

            valuesMatch = key.Illuminated == returnKeyAudit.Illuminated;
            Assert.IsTrue(valuesMatch, "Illuminated of return audit object did not match object");

            valuesMatch = key.PersonID == returnKeyAudit.PersonID;
            Assert.IsTrue(valuesMatch, "PersonID of return audit object did not match object");

            valuesMatch = key.State == returnKeyAudit.State;
            Assert.IsTrue(valuesMatch, "State of return audit object did not match  object");
        }