Пример #1
0
        public void GetAll_TestClassObjectPassed_ProperMethodCalled()
        {
            // Arrange
            var testObject = new TestClass()
            {
                Id = 1
            };
            var testList = new List <TestClass>()
            {
                testObject
            };

            var dbSetMock = ServiceTestsHelper.GetMockDbSet <TestClass>(testList);

            var context = new Mock <QuoteDbContext>();

            context.Setup(x => x.Set <TestClass>()).Returns(dbSetMock.Object);

            // Act
            var repository = new Repository <TestClass>(context.Object);
            var result     = repository.GetAll();

            // Assert
            Assert.Equal(testList, result.ToList());
        }
Пример #2
0
        public void Get_Frase_Dia()
        {
            // Arrange
            var frase = new Frase
            {
                Id        = 1,
                Texto     = "El testing es un belleza",
                Autor     = "Juan David Pareja Soto",
                Categoria = new Categoria
                {
                    Id     = 1,
                    Nombre = "Frases Motivacionales"
                },
                Fecha = new DateTime(2019, 10, 25)
            };

            var context   = new Mock <QuoteDbContext>();
            var dbSetMock = ServiceTestsHelper.GetMockDbSet <Frase>(frase);

            context.Setup(x => x.Set <Frase>()).Returns(dbSetMock.Object);
            var repository = new Repository <Frase>(context.Object);

            // Act
            var service  = new QuoteService(repository);
            var fraseDia = service.GetByDate(new DateTime(2019, 10, 25));


            //Assert
            Assert.Equal(frase, fraseDia);
        }
Пример #3
0
        public void Get_Frase_Semana()
        {
            DateTime enero1 = new DateTime(2019, 01, 01);
            // Arrange
            List <Frase> frases = new List <Frase>();

            for (int i = 0; i < 365; i++)
            {
                frases.Add(new Frase
                {
                    Id        = i,
                    Texto     = $"El testing es un belleza {i}",
                    Autor     = "Juan David Pareja Soto",
                    Categoria = new Categoria
                    {
                        Id     = 1,
                        Nombre = "Frases Motivacionales"
                    },
                    Fecha = enero1
                });
                enero1 = enero1.AddDays(1);
            }
            var fraseHoy = new Frase
            {
                Id        = 1,
                Texto     = $"El testing es un belleza 1",
                Autor     = "Juan David Pareja Soto",
                Categoria = new Categoria
                {
                    Id     = 1,
                    Nombre = "Frases Motivacionales"
                },
                Fecha = new DateTime(2019, 01, 01)
            };
            var context   = new Mock <QuoteDbContext>();
            var dbSetMock = ServiceTestsHelper.GetMockDbSet <Frase>(frases);

            context.Setup(x => x.Set <Frase>()).Returns(dbSetMock.Object);
            var repository = new Repository <Frase>(context.Object);

            // Act
            var service  = new QuoteService(repository);
            var fraseDia = service.GetByWeek(new DateTime(2019, 01, 01), new DateTime(2019, 01, 07));

            //Assert
            Assert.Equal(7, fraseDia.Count());
        }
Пример #4
0
        public void Add_TestClassObjectPassed_ProperMethodCalled()
        {
            // Arrange
            var testObject = new TestClass();

            var context   = new Mock <QuoteDbContext>();
            var dbSetMock = ServiceTestsHelper.GetMockDbSet <TestClass>(testObject);

            context.Setup(x => x.Set <TestClass>()).Returns(dbSetMock.Object);
            // Act
            var repository = new Repository <TestClass>(context.Object);

            repository.Add(testObject);

            //Assert
            context.Verify(x => x.Set <TestClass>());
            dbSetMock.Verify(x => x.Add(It.Is <TestClass>(y => y == testObject)));
        }