Ejemplo n.º 1
0
        public void EditTable_ExceptionFromDataAccess()
        {
            //Arrange Changes
            var newNumber      = 2;
            var newDescription = "Po prawej";

            //Arrange Table
            var oldNumber      = 1;
            var oldDescription = "Po lewej";
            var table          = new MoqTable(1, oldNumber, oldDescription);

            var mock = new Mock <IManagerDataAccess>();

            mock.Setup(m => m.EditTable(It.IsAny <Table>())).Throws(new Exception());

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.EditTable(table, newNumber, newDescription);

            //Assert
            Assert.IsFalse(result);
            Assert.AreEqual(table.Number, oldNumber);
            Assert.AreEqual(table.Description, oldDescription);
        }
Ejemplo n.º 2
0
        public void AddTable_ValidExample()
        {
            //Arrange Table
            var table = new MoqTable(1, 1, "Po lewej");

            var mock = new Mock <IManagerDataAccess>();

            mock.Setup(m => m.AddTable(It.IsAny <int>(), It.IsAny <string>())).Returns(table);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.AddTable(table.Number, table.Description);

            //Assert
            Assert.AreEqual(result, table);
        }
Ejemplo n.º 3
0
        public void GetAllTables_ValidExample()
        {
            //Arrange List of Categories
            var Tables = new List <MoqTable>();

            var f1 = new MoqTable(1, 1, "Po lewej");
            var f2 = new MoqTable(2, 2, "Po środku");
            var f3 = new MoqTable(3, 3, "Po prawej");

            Tables.Add(f1);
            Tables.Add(f2);
            Tables.Add(f3);

            var mock = new Mock <IManagerDataAccess>();

            mock.Setup(m => m.GetTables()).Returns(Tables);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var ReturnedTables     = BarDataModel.GetAllTables();
            var ReturnedTablesCast = ReturnedTables.Cast <MoqTable>().ToList();

            //Asserts
            Assert.IsNotNull(ReturnedTables);

            Assert.AreEqual(ReturnedTablesCast[0].Id, f1.Id);
            Assert.AreEqual(ReturnedTablesCast[0].Number, f1.Number);
            Assert.AreEqual(ReturnedTablesCast[0].Description, f1.Description);

            Assert.AreEqual(ReturnedTablesCast[1].Id, f2.Id);
            Assert.AreEqual(ReturnedTablesCast[1].Number, f2.Number);
            Assert.AreEqual(ReturnedTablesCast[1].Description, f2.Description);

            Assert.AreEqual(ReturnedTablesCast[2].Id, f3.Id);
            Assert.AreEqual(ReturnedTablesCast[2].Number, f3.Number);
            Assert.AreEqual(ReturnedTablesCast[2].Description, f3.Description);
        }
Ejemplo n.º 4
0
        public void EditTable_ValidExample()
        {
            //Arrange Changes
            var newNumber      = 2;
            var newDescription = "Po prawej";

            //Arrange Table
            var table = new MoqTable(1, 1, "Po lewej");

            var mock = new Mock <IManagerDataAccess>();

            mock.Setup(m => m.EditTable(It.IsAny <Table>())).Returns(true);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.EditTable(table, newNumber, newDescription);

            //Assert
            Assert.IsTrue(result);
            Assert.AreEqual(table.Number, newNumber);
            Assert.AreEqual(table.Description, newDescription);
        }
Ejemplo n.º 5
0
        public void GetAllTables_ValidExample()
        {
            //Arrange List of Categories
            var Tables = new List<MoqTable>();

            var f1 = new MoqTable(1, 1, "Po lewej");
            var f2 = new MoqTable(2, 2, "Po środku");
            var f3 = new MoqTable(3, 3, "Po prawej");

            Tables.Add(f1);
            Tables.Add(f2);
            Tables.Add(f3);

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.GetTables()).Returns(Tables);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var ReturnedTables = BarDataModel.GetAllTables();
            var ReturnedTablesCast = ReturnedTables.Cast<MoqTable>().ToList();

            //Asserts
            Assert.IsNotNull(ReturnedTables);

            Assert.AreEqual(ReturnedTablesCast[0].Id, f1.Id);
            Assert.AreEqual(ReturnedTablesCast[0].Number, f1.Number);
            Assert.AreEqual(ReturnedTablesCast[0].Description, f1.Description);

            Assert.AreEqual(ReturnedTablesCast[1].Id, f2.Id);
            Assert.AreEqual(ReturnedTablesCast[1].Number, f2.Number);
            Assert.AreEqual(ReturnedTablesCast[1].Description, f2.Description);

            Assert.AreEqual(ReturnedTablesCast[2].Id, f3.Id);
            Assert.AreEqual(ReturnedTablesCast[2].Number, f3.Number);
            Assert.AreEqual(ReturnedTablesCast[2].Description, f3.Description);
        }
Ejemplo n.º 6
0
        public void EditTable_ValidExample()
        {
            //Arrange Changes
            var newNumber = 2;
            var newDescription = "Po prawej";

            //Arrange Table
            var table = new MoqTable(1, 1, "Po lewej");

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.EditTable(It.IsAny<Table>())).Returns(true);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.EditTable(table, newNumber, newDescription);

            //Assert
            Assert.IsTrue(result);
            Assert.AreEqual(table.Number, newNumber);
            Assert.AreEqual(table.Description, newDescription);
        }
Ejemplo n.º 7
0
        public void EditTable_ExceptionFromDataAccess()
        {
            //Arrange Changes
            var newNumber = 2;
            var newDescription = "Po prawej";

            //Arrange Table
            var oldNumber = 1;
            var oldDescription = "Po lewej";
            var table = new MoqTable(1, oldNumber, oldDescription);

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.EditTable(It.IsAny<Table>())).Throws(new Exception());

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.EditTable(table, newNumber, newDescription);

            //Assert
            Assert.IsFalse(result);
            Assert.AreEqual(table.Number, oldNumber);
            Assert.AreEqual(table.Description, oldDescription);
        }
Ejemplo n.º 8
0
        public void AddTable_ValidExample()
        {
            //Arrange Table
            var table = new MoqTable(1, 1, "Po lewej");

            var mock = new Mock<IManagerDataAccess>();
            mock.Setup(m => m.AddTable(It.IsAny<int>(), It.IsAny<string>())).Returns(table);

            //Arrange Bar Data Model
            var BarDataModel = new BarDataModel(mock.Object);

            //Act
            var result = BarDataModel.AddTable(table.Number, table.Description);

            //Assert
            Assert.AreEqual(result, table);
        }