Esempio n. 1
0
        public void Index_Action_RightResult()
        {
            //Arrange
            Guid guid1 = Guid.NewGuid();
            Guid guid2 = Guid.NewGuid();
            Guid guid3 = Guid.NewGuid();
            Guid guid4 = Guid.NewGuid();

            string ProcNumb1 = "Proc1";
            string ProcNumb2 = "Proc2";
            string ProcNumb3 = "Proc3";
            string ProcNumb4 = "Proc4";

            IEnumerable <CPUdto> cpus = new List <CPUdto>
            {
                new CPUdto {
                    ProductGuid = guid1, ProcessorNumber = ProcNumb1
                },
                new CPUdto {
                    ProductGuid = guid2, ProcessorNumber = ProcNumb2
                },
                new CPUdto {
                    ProductGuid = guid3, ProcessorNumber = ProcNumb3
                },
                new CPUdto {
                    ProductGuid = guid4, ProcessorNumber = ProcNumb4
                }
            };

            Service.Setup(x => x.GetCPUs()).Returns(cpus);

            CPUsController controller = new CPUsController(Service.Object, Mapper);
            //Act
            var result = controller.Index() as ViewResult;

            //Assert
            Assert.IsInstanceOfType(result.Model, typeof(List <CPUViewModel>));
            List <CPUViewModel> resultCPUs = (List <CPUViewModel>)result.Model;

            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProcessorNumber == ProcNumb1));
            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProcessorNumber == ProcNumb2));
            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProcessorNumber == ProcNumb3));
            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProcessorNumber == ProcNumb4));
            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProductGuid == guid1));
            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProductGuid == guid2));
            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProductGuid == guid3));
            Assert.IsNotNull(resultCPUs.
                             Find(x => x.ProductGuid == guid4));
        }
Esempio n. 2
0
        public void Delete_DeleteCPU_ServiceMethodWereCalled()
        {
            //Arrange
            Guid   guid1     = Guid.NewGuid();
            string ProcNumb1 = "Proc1";

            CPUViewModel cpu = new CPUViewModel {
                ProductGuid = guid1, ProcessorNumber = ProcNumb1
            };

            //Service.Setup(x => x.GetCPUs()).Returns(cpu);

            CPUsController controller = new CPUsController(Service.Object, Mapper);
            //Act
            var result = controller.DeleteConfirmed(guid1) as ViewResult;

            //Assert
            Service.Verify(x => x.DeleteCPU(guid1));
        }
Esempio n. 3
0
        public void Create_AddCPU_ReturneRightModel()
        {
            //Arrange
            Guid   guid1     = Guid.NewGuid();
            string ProcNumb1 = "Proc1";

            CPUViewModel cpu = new CPUViewModel {
                ProductGuid = guid1, ProcessorNumber = ProcNumb1
            };

            //Service.Setup(x => x.GetCPUs()).Returns(cpu);

            CPUsController controller = new CPUsController(Service.Object, Mapper);
            //Act
            var result = controller.Create(cpu) as ViewResult;

            //Assert
            Service.Verify(x => x.SaveCPU(It.IsAny <CPUdto>()));
        }