public void ThrowArgumentNullException_WhenSportscardsIsNull()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var data = new List <Sportscard>
            {
                new Sportscard {
                    CreatedOn = DateTime.Today.AddDays(-1)
                }
            };

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

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

            dbContextMock
            .Setup(x => x.Sportscards)
            .Returns((IDbSet <Sportscard>)null);

            var sportscardDto = new SportscardDto()
            {
                CompanyId = Guid.NewGuid()
            };

            var sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentNullException>(() => sportscardService.GetAllSportscards());
        }
        public void InvokeSaveChangesMethod_WhenSportscardWithTheSameClientNameAndCompanyExists()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var client = new Client()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271325"),
                FirstName = "Pesho",
                LastName  = "Peshev"
            };

            var company = new Company()
            {
                Id   = new Guid("aa992eab-b53c-4f7d-a5f3-a204d560eb93"),
                Name = "Meka M"
            };


            var expectedSportscard = new Sportscard()
            {
                ClientId  = client.Id,
                CompanyId = company.Id,
                IsDeleted = true
            };

            var data = new List <Sportscard>
            {
                new Sportscard
                {
                    ClientId  = client.Id,
                    Client    = client,
                    CompanyId = company.Id,
                    Company   = company,
                    IsDeleted = false,
                    DeletedOn = DateTime.Now.Date
                }
            };

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

            mockSet.SetupData(data);

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

            var sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act
            sportscardService.DeleteSportscard(client.FirstName, client.LastName, company.Name);

            //Assert
            dbContextMock.Verify(x => x.SaveChanges(), Times.Once);
            Assert.AreEqual(expectedSportscard.IsDeleted, true);
        }
        public void ThrowArgumentNullException_WhenInvokedWithInvalidParameter()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            SportscardDto sportscardDto     = null;
            var           sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentNullException>(() => sportscardService.AddSportscard(sportscardDto));
        }
        public void ThrowArgumentNullException_WhenSportscardWithTheGivenCompanyNameDoesNotExist()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var client = new Client()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271325"),
                FirstName = "Pesho",
                LastName  = "Peshev"
            };

            var company = new Company()
            {
                Id   = new Guid("aa992eab-b53c-4f7d-a5f3-a204d560eb93"),
                Name = "Meka M"
            };


            var expectedSportscard = new Sportscard()
            {
                ClientId  = client.Id,
                CompanyId = company.Id,
                IsDeleted = true
            };

            var data = new List <Sportscard>
            {
                new Sportscard
                {
                    ClientId  = client.Id,
                    Client    = client,
                    CompanyId = company.Id,
                    Company   = company,
                    IsDeleted = false,
                    DeletedOn = DateTime.Now.Date
                }
            };

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

            mockSet.SetupData(data);

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

            var sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act
            Assert.ThrowsException <ArgumentNullException>(() => sportscardService.DeleteSportscard(client.FirstName, client.LastName, "TEST"));
        }
        public void CreateInstance_WhenInvokedWithValidParameters()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            //Act
            var clientService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Assert
            Assert.IsNotNull(clientService);
            Assert.IsInstanceOfType(clientService, typeof(ISportscardService));
        }
        public void AddSportscardToDabatase_WhenInvokedWithValidParameters()
        {
            //Arrange
            var dbContextMock      = new Mock <ISportscardSystemDbContext>();
            var mapperMock         = new Mock <IMapper>();
            var expectedSportscard = new Sportscard()
            {
                CompanyId = Guid.NewGuid()
            };

            var data = new List <Sportscard>
            {
                new Sportscard {
                    CreatedOn = DateTime.Today.AddDays(-1)
                }
            };

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

            mockSet.SetupData(data);
            mockSet.Setup(m => m.Add(It.IsAny <Sportscard>()));

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

            var sportscardDto = new SportscardDto()
            {
                CompanyId = Guid.NewGuid()
            };

            mapperMock
            .Setup(x => x.Map <Sportscard>(sportscardDto))
            .Returns(expectedSportscard);

            var sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act
            sportscardService.AddSportscard(sportscardDto);

            //Assert
            mockSet.Verify(x => x.Add(expectedSportscard), Times.Once);
        }
        public void ReturnIEnumerableOfSportscardsDto_WhenCollectionIsNotNull()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

            var data = new List <Sportscard>
            {
                new Sportscard {
                    CreatedOn = DateTime.Today.AddDays(-1)
                }
            };

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

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

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

            var sportscardDto = new SportscardDto()
            {
                CompanyId = Guid.NewGuid()
            };

            var sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act
            var sportscards = sportscardService.GetAllSportscards();

            //Assert
            Assert.AreEqual(data.Count, sportscards.Count());
            Assert.IsNotNull(sportscards);
            Assert.IsInstanceOfType(sportscards, typeof(IEnumerable <ISportscardDto>));
        }
        public void ThrowArgumentNullException_WhenSportscardsIsNull()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

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

            var secondClient = new Client()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271323"),
                FirstName = "Pesho",
                LastName  = "Peshev",
                IsDeleted = false
            };

            var firstCompany = new Company()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271320"),
                Name      = "Progress",
                IsDeleted = false
            };

            var secondCompany = new Company()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271319"),
                Name      = "Telerik",
                IsDeleted = false
            };

            var data = new List <Sportscard>()
            {
                new Sportscard
                {
                    Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271322"),
                    Client    = firstClient,
                    ClientId  = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271324"),
                    Company   = firstCompany,
                    CompanyId = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271320"),
                    IsDeleted = false
                },
                new Sportscard
                {
                    Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271321"),
                    Client    = secondClient,
                    ClientId  = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271323"),
                    Company   = secondCompany,
                    CompanyId = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271319"),
                    IsDeleted = false
                }
            };

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

            mockSet.SetupData(data);

            Mapper.Reset();
            AutomapperConfiguration.Initialize();

            dbContextMock
            .Setup(x => x.Sportscards)
            .Returns((IDbSet <Sportscard>)null);

            var sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act && Assert
            Assert.ThrowsException <ArgumentNullException>(() => sportscardService.GetReport());
        }
        public void ReturnCollectionOfISportscardViewDto_WhenAnySportscardsExist()
        {
            //Arrange
            var dbContextMock = new Mock <ISportscardSystemDbContext>();
            var mapperMock    = new Mock <IMapper>();

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

            var secondClient = new Client()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271323"),
                FirstName = "Pesho",
                LastName  = "Peshev",
                IsDeleted = false
            };

            var firstCompany = new Company()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271320"),
                Name      = "Progress",
                IsDeleted = false
            };

            var secondCompany = new Company()
            {
                Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271319"),
                Name      = "Telerik",
                IsDeleted = false
            };

            var data = new List <Sportscard>
            {
                new Sportscard
                {
                    Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271322"),
                    Client    = firstClient,
                    ClientId  = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271324"),
                    Company   = firstCompany,
                    CompanyId = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271320"),
                    IsDeleted = false
                },
                new Sportscard
                {
                    Id        = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271321"),
                    Client    = secondClient,
                    ClientId  = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271323"),
                    Company   = secondCompany,
                    CompanyId = new Guid("db97a0eb-9411-4f1d-9ead-3997e6271319"),
                    IsDeleted = false
                }
            };

            var dataClients = new List <Client>();

            dataClients.Add(firstClient);
            dataClients.Add(secondClient);

            var dataCompanies = new List <Company>();

            dataCompanies.Add(firstCompany);
            dataCompanies.Add(secondCompany);

            var mockSet          = new Mock <DbSet <Sportscard> >();
            var mockSetClients   = new Mock <DbSet <Client> >();
            var mockSetCompanies = new Mock <DbSet <Company> >();

            mockSet.SetupData(data);
            mockSetClients.SetupData(dataClients);
            mockSetCompanies.SetupData(dataCompanies);

            Mapper.Reset();
            AutomapperConfiguration.Initialize();

            dbContextMock
            .Setup(x => x.Clients)
            .Returns(mockSetClients.Object);

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

            dbContextMock
            .Setup(x => x.Companies)
            .Returns(mockSetCompanies.Object);

            var sportscardService = new SportscardService(dbContextMock.Object, mapperMock.Object);

            //Act
            var sportscardsReport = sportscardService.GetReport();

            //Assert
            Assert.AreEqual(2, sportscardsReport.Count());
        }