Пример #1
0
        public void ReturnEmptyCollection_WhenThereIsNoVisitsFromTheGivenDate()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var client = new Client()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271324"),
                FirstName = "Georgi",
                LastName  = "Georgiev",
                IsDeleted = false,
                Visits    = new List <Visit>()
            };

            var visit = new Visit()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271324"),
                Client    = client,
                IsDeleted = false,
                Sport     = new Sport()
                {
                    Name = "Gym"
                },
                Sportshall = new Sportshall()
                {
                    Name = "Topfit"
                },
                CreatedOn = DateTime.Parse("2018-03-27")
            };

            var data = new List <Visit>
            {
                new Visit()
                {
                    Id     = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271323"),
                    Client = new Client()
                    {
                        FirstName = "Pesho",
                        LastName  = "Peshev"
                    },
                    IsDeleted = false,
                    Sport     = new Sport()
                    {
                        Name = "Yoga"
                    },
                    Sportshall = new Sportshall()
                    {
                        Name = "Topfit"
                    },
                    CreatedOn = DateTime.Parse("2018-03-28")
                },
                new Visit()
                {
                    Id     = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271322"),
                    Client = new Client()
                    {
                        FirstName = "Gosho",
                        LastName  = "Goshev"
                    },
                    IsDeleted = false,
                    Sport     = new Sport()
                    {
                        Name = "Boxing"
                    },
                    Sportshall = new Sportshall()
                    {
                        Name = "Topfit"
                    },
                    CreatedOn = DateTime.Parse("2018-02-28")
                }
            };

            data.Add(visit);

            var mockSet = new Mock <DbSet <Visit> >();

            mockSet.SetupData(data);
            Mapper.Reset();
            AutomapperConfiguration.Initialize();

            dbContextMock
            .Setup(x => x.Visits)
            .Returns(mockSet.Object);

            var sportService = new SportService(dbContextMock.Object, mapperMock.Object);

            //Act
            var sportVisits = sportService.GetSportVisitsFrom("Gym", "2018-03-29");

            //Assert
            Assert.AreEqual(0, sportVisits.Count());
        }
Пример #2
0
        public void ThrowArgumentException_WhenInvokedWithInvalidEmptyDateParameter()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var client = new Client()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271324"),
                FirstName = "Georgi",
                LastName  = "Georgiev",
                IsDeleted = false,
                Visits    = new List <Visit>()
            };

            var visit = new Visit()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271324"),
                Client    = client,
                IsDeleted = false,
                Sport     = new Sport()
                {
                    Name = "Gym"
                },
                Sportshall = new Sportshall()
                {
                    Name = "Topfit"
                },
                CreatedOn = DateTime.Now.Date
            };

            var data = new List <Visit>
            {
                new Visit()
                {
                    Id     = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271323"),
                    Client = new Client()
                    {
                        FirstName = "Pesho",
                        LastName  = "Peshev"
                    },
                    IsDeleted = false,
                    Sport     = new Sport()
                    {
                        Name = "Yoga"
                    },
                    Sportshall = new Sportshall()
                    {
                        Name = "Topfit"
                    },
                    CreatedOn = DateTime.Now.AddDays(-1)
                },
                new Visit()
                {
                    Id     = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271322"),
                    Client = new Client()
                    {
                        FirstName = "Gosho",
                        LastName  = "Goshev"
                    },
                    IsDeleted = false,
                    Sport     = new Sport()
                    {
                        Name = "Boxing"
                    },
                    Sportshall = new Sportshall()
                    {
                        Name = "Topfit"
                    },
                    CreatedOn = DateTime.Now.AddDays(-10)
                }
            };

            data.Add(visit);

            var mockSet = new Mock <DbSet <Visit> >();

            mockSet.SetupData(data);
            Mapper.Reset();
            AutomapperConfiguration.Initialize();

            dbContextMock
            .Setup(x => x.Visits)
            .Returns(mockSet.Object);

            var sportService = new SportService(dbContextMock.Object, mapperMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentException>(() => sportService.GetSportVisitsFrom("Topfit", string.Empty));
        }