public void TestGetPackagesWithRecipientAndStatus_WithTestData_ShoudGetAllPackagesWithRecipientAndStatus()
        {
            var factory  = new PandaDbContextFactory();
            var context  = factory.CreatePandaDbContext();
            var services = new PackagesService(context);

            SeedDbWithPackages(context);
            SeedDbWithPackageStuses(context);
            SeedDbWithRecipients(context);

            MakeTheConnectionBetweenTheEntities(context);

            var expectedData = context.Packages
                               .Include(package => package.Recipient)
                               .Include(package => package.Status)
                               .ToList();

            var actualData = services.GetPackagesWithRecipientAndStatus().ToList();

            foreach (var package in actualData)
            {
                Assert.Contains(expectedData, x => x.Recipient.Id == package.Recipient.Id &&
                                x.Status == package.Status);
            }
        }
Exemplo n.º 2
0
        public void TestGetUser_WithExistentUsername_ShouldReturnUser()
        {
            var factory = new PandaDbContextFactory();

            var context = factory.CreatePandaDbContext();

            this.SeedTestData(context);

            var usersService = new UsersService(context);

            string testUsername = "******";

            var expectedData = GetTestData().SingleOrDefault(user => user.UserName == testUsername);
            var actualData   = usersService.GetUser(testUsername);

            AssertExtensions.EqualsWithMessage(
                expectedData.UserName,
                actualData.UserName,
                "UsersService GetUser() does not work properly!");


            AssertExtensions.EqualsWithMessage(
                expectedData.Email,
                actualData.Email,
                "UsersService GetUser() does not work properly!");


            AssertExtensions.EqualsWithMessage(
                expectedData.UserRole.Name,
                actualData.UserRole.Name,
                "UsersService GetUser() does not work properly!");
        }
        public void TestAddReceipt_WithTestData_ShoudAddNewPackageInToDb()
        {
            var factory  = new PandaDbContextFactory();
            var context  = factory.CreatePandaDbContext();
            var services = new ReceiptsService(context);

            services.AddReceipt(new Receipt());


            var actualData = context.Receipts.Count();

            Assert.True(actualData == 1, "PackagesService AddPackage() method does not work porperly!");
        }
Exemplo n.º 4
0
        public void TestGetAllUsers_WithoutAnyData_ShouldReturnEmptyList()
        {
            var factory = new PandaDbContextFactory();

            var context = factory.CreatePandaDbContext();


            var usersService = new UsersService(context);

            var actualData = usersService.GetAllUsers();

            Assert.True(actualData.Count == 0, "UsersService GetAllUsers() method does not work properly!");
        }
        public void TestGetPackageStatus_WithTestData_ShoudGetPackageStatusWithName()
        {
            var factory  = new PandaDbContextFactory();
            var context  = factory.CreatePandaDbContext();
            var services = new PackagesService(context);

            SeedDbWithPackageStuses(context);

            var packageStatus = context.PackageStatus.FirstOrDefault();


            var actualData   = services.GetPackageStatus(packageStatus.Name);
            var expectedData = packageStatus;

            Assert.True(actualData.Id == expectedData.Id &&
                        actualData.Name == expectedData.Name);
        }
        public void TestAddPackage_WithTestData_ShoudAddNewPackageInToDb()
        {
            var factory = new PandaDbContextFactory();
            var context = factory.CreatePandaDbContext();

            var services = new PackagesService(context);

            services.AddPackage(new Package());
            var packeges = context.Packages.ToList();

            var actualData   = packeges.Count;
            var expectedData = 1;


            Assert.True(expectedData == actualData,
                        "PackagesService AddPackage() method does not work porperly!");
        }
Exemplo n.º 7
0
        public void TestGetUser_WithNonExistentUsername_ShouldReturnNull()
        {
            var factory = new PandaDbContextFactory();

            var context = factory.CreatePandaDbContext();

            this.SeedTestData(context);

            var usersService = new UsersService(context);

            string testUsername = "******";

            var actualData = usersService.GetUser(testUsername);

            Assert.True(actualData == null,
                        "UsersService GetUser() does not work properly!");
        }
        public void TestGetPackage_WithTestData_ShoudGetPackageWithId()
        {
            var factory  = new PandaDbContextFactory();
            var context  = factory.CreatePandaDbContext();
            var services = new PackagesService(context);

            SeedDbWithPackages(context);

            var package = context.Packages.FirstOrDefault();


            var actualData   = services.GetPackage(package.Id);
            var expectedData = package;

            Assert.True(actualData.Id == expectedData.Id &&
                        actualData.Weight == expectedData.Weight &&
                        actualData.Description == expectedData.Description &&
                        actualData.ShippingAddress == expectedData.ShippingAddress);
        }
        public void GetAllReceiptsWithRecipientAndPackage_WithTestData_ShoudGetAllReceiptsWithRecipientAndPackage()
        {
            var factory  = new PandaDbContextFactory();
            var context  = factory.CreatePandaDbContext();
            var services = new ReceiptsService(context);

            var expectedData = context.Receipts
                               .Include(receipt => receipt.Package)
                               .Include(receipt => receipt.Recipient)
                               .ToList();

            var actualData = services.GetAllReceiptsWithRecipientAndPackage();


            foreach (var receipt in actualData)
            {
                Assert.Contains(expectedData, x => x.Package.Id == receipt.Package.Id &&
                                x.Recipient.Id == receipt.Recipient.Id);
            }
        }
        public void TestGetAllReceiptsWithRecipient_WithTestData_ShoudGetAllReceiptsWithRecipient()
        {
            var factory  = new PandaDbContextFactory();
            var context  = factory.CreatePandaDbContext();
            var services = new ReceiptsService(context);

            SeedDbWithReceipts(context);
            SeedDbWithRecipients(context);
            MakeConnectionBetweenTheEntities(context);

            var actualData   = services.GetAllReceiptsWithRecipient().ToList();
            var expectedData = context.Receipts
                               .Include(receipt => receipt.Recipient)
                               .ToList();

            foreach (var receipt in expectedData)
            {
                Assert.Contains(actualData, x =>
                                x.Recipient.UserName == receipt.Recipient.UserName &&
                                x.Recipient.Email == x.Recipient.Email);
            }
        }
        public void TestUpdatePackage_WithTestData_ShoudUpdatePackage()
        {
            var factory = new PandaDbContextFactory();
            var context = factory.CreatePandaDbContext();

            var    services  = new PackagesService(context);
            double newWeight = 9999;

            SeedDbWithPackages(context);

            var package = context.Packages.FirstOrDefault();

            package.Weight = newWeight;
            services.UpdatePackage(package);


            var actualData   = context.Packages.FirstOrDefault().Weight;
            var expectedData = newWeight;


            Assert.True(expectedData == actualData,
                        "PackagesService UpdatePackage() method does not work porperly!");
        }
Exemplo n.º 12
0
        public void TestGetAllUsers_WithTestData_ShouldReturnAllUsers()
        {
            var factory = new PandaDbContextFactory();

            var context = factory.CreatePandaDbContext();

            this.SeedTestData(context);

            var usersService = new UsersService(context);

            var expectedData = GetTestData();
            var actualData   = usersService.GetAllUsers();

            Assert.Equal(expectedData.Count, actualData.Count);

            foreach (var actualUser in actualData)
            {
                Assert.True(expectedData.Any(x =>
                                             x.UserName == actualUser.UserName &&
                                             x.Email == actualUser.Email &&
                                             x.UserRole.Name == actualUser.UserRole.Name),
                            "UsersService GetAllUsers() method does not work porperly!");
            }
        }