public async Task GetAllAuctionHouses_WithDummData_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "AuctionService GetAllAuctionHouses does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.auctionHouseService = new AuctionHouseService(context);

            List <AuctionHouse> actualResults = await
                                                this.auctionHouseService.GetAllAuctionHouses().ToListAsync();

            List <AuctionHouse> expectedResults = GetDummyData();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.Address == actualEntry.Address, errorMessagePrefix + "Adresses are different.");
                Assert.True(expectedEntry.Description == actualEntry.Description, errorMessagePrefix + "Descriptions are different.");
                Assert.True(expectedEntry.City.Name == actualEntry.City.Name, errorMessagePrefix + "City names are different.");
            }
        }
Example #2
0
        public async Task Delete_WithWrongItemNameData_ShouldThrowException()
        {
            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);

            var user = context.Users.First();

            var item = new Item
            {
                Id            = Guid.NewGuid().ToString(),
                Name          = "Wooden axe",
                Category      = Category.Other,
                StartingPrice = 13.13M,
                BuyOutPrice   = 34.33M,
                StartTime     = DateTime.UtcNow,
                EndTime       = DateTime.UtcNow.AddDays(1),
                Description   = "Legit",
                AuctionUserId = user.Id
            };

            context.Items.Add(item);

            string missingItem = "Missing";

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.userService.Delete(user.Id, missingItem));
        }
        public async Task GetAllItems_WithDummData_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "ItemService GetAllItems does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            List <Item> actualResults = await
                                        this.itemService.GetAllItems().ToListAsync();

            List <Item> expectedResults = GetDummyData();

            for (int i = 0; i < expectedResults.Count; i++)
            {
                var expectedEntry = expectedResults[i];
                var actualEntry   = actualResults[i];

                Assert.True(expectedEntry.Name == actualEntry.Name, errorMessagePrefix + "Names are different.");
                Assert.True(expectedEntry.Description == actualEntry.Description, errorMessagePrefix + "Descriptions are different.");
                Assert.True(expectedEntry.StartingPrice == actualEntry.StartingPrice, errorMessagePrefix + "Starting prices are different.");
                Assert.True(expectedEntry.BuyOutPrice == actualEntry.BuyOutPrice, errorMessagePrefix + "Buy out prices are different.");
            }
        }
Example #4
0
        public async Task CreateBid_WithIncorrectBiddingTime_ShouldReturnFaslse()
        {
            string errorMessagePrefix = "BidService CreateBid() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);
            this.bidService  = new BidService(context, userService);

            var item = new Item
            {
                Id            = "BoneId",
                Name          = "Bone",
                Category      = Category.Other,
                StartingPrice = 13.13M,
                BuyOutPrice   = 34.33M,
                StartTime     = DateTime.UtcNow,
                EndTime       = DateTime.UtcNow.AddMinutes(-1),
                Description   = "Legit",
            };

            context.Items.Add(item);
            context.SaveChanges();

            var dummyUserId = "Hugo";
            var dummyItem   = context.Items.First(x => x.Name == "Bone");
            var result      = await this.bidService.CreateBid(dummyItem, dummyUserId, 20);

            Assert.False(result, errorMessagePrefix);
        }
        public async Task Buy_WithCorrectId_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "ItemService Buy() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var dummyItemId = "EyePatchId";

            var dummyUser = new AuctionUser
            {
                Id = "Hugo"
            };

            context.Users.Add(dummyUser);

            bool actualResult = await this.itemService.Buy(dummyItemId, dummyUser.Id);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task Create_WithCorrectData_ShouldReturnSuccessfullyCreate()
        {
            string errorMessagePrefix = "ItemService GetAllItems does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService    = new UserService(context);
            this.receiptService = new ReceiptService(context);

            Account cloudinaryCredentials = new Account(
                "auction-cloud",
                "245777487727621",
                "VcLN0NRPB7qs0WZv_U2AxMR79sc");

            var cloudinary = new Cloudinary(cloudinaryCredentials);

            this.cloudinaryService = new CloudinaryService(cloudinary);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var user = new AuctionUser
            {
                Id = "Hugo"
            };

            context.Users.Add(user);

            using (var stream = File.OpenRead(@"./Images/test.jpg"))
            {
                var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(@"./Images/test.jpg"))
                {
                    Headers     = new HeaderDictionary(),
                    ContentType = "image/jpeg"
                };

                var dummyItem = new ItemCreateInputModel
                {
                    Name            = "Stick",
                    Category        = "Other",
                    Description     = "Somethin",
                    AuctionDuration = 12,
                    StartingPrice   = 334M,
                    BuyOutPrice     = 3412M,
                    Picture         = file,
                    AuctionHouse    = "Ember"
                };



                bool actualResult = await this.itemService.Create(dummyItem, user.Id);

                Assert.True(actualResult, errorMessagePrefix);
            }
        }
        public async Task GetAllAuctionHouses_WithDummData_ShouldZeroResults()
        {
            string errorMessagePrefix = "CityService GetAllCities does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            this.cityService = new CityService(context);

            List <City> actualResults = await
                                        this.cityService.GetAllCities().ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix);
        }
Example #8
0
        public async Task GetById_WithNonExistingId_ShouldReturnNull()
        {
            string errorMessagePrefix = "UserService GetById() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);

            var actualData = await this.userService.GetById("Missing");

            Assert.True(actualData == null, errorMessagePrefix);
        }
        public async Task Create_WithMissingAuctionHouse_ShouldThrowException()
        {
            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService    = new UserService(context);
            this.receiptService = new ReceiptService(context);

            Account cloudinaryCredentials = new Account(
                "auction-cloud",
                "245777487727621",
                "VcLN0NRPB7qs0WZv_U2AxMR79sc");

            var cloudinary = new Cloudinary(cloudinaryCredentials);

            this.cloudinaryService = new CloudinaryService(cloudinary);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var user = new AuctionUser
            {
                Id = "Hugo"
            };

            context.Users.Add(user);

            using (var stream = File.OpenRead(@"./Images/test.jpg"))
            {
                var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(@"./Images/test.jpg"))
                {
                    Headers     = new HeaderDictionary(),
                    ContentType = "image/jpeg"
                };

                var dummyItem = new ItemCreateInputModel
                {
                    Name            = "Stick",
                    Category        = "Other",
                    Description     = "Somethin",
                    AuctionDuration = 12,
                    StartingPrice   = 334M,
                    BuyOutPrice     = 3412M,
                    Picture         = file,
                    AuctionHouse    = "Wrong"
                };


                await Assert.ThrowsAsync <ArgumentNullException>(() => this.itemService.Create(dummyItem, user.Id));
            }
        }
        public async Task GetById_WithNonExistingId_ShouldThrowException()
        {
            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var itemId = "Missing";

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.itemService.GetById(itemId));
        }
        public async Task GetReceiptsById_MissingId_ShouldReturnZeroResults()
        {
            string errorMessagePrefix = "ReceiptService GetReceiptsById does not work properly.";
            string userId             = "Missing";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.receiptService = new ReceiptService(context);

            var actualReceipts = await this.receiptService.GetReceiptsById(userId).ToListAsync();

            Assert.True(actualReceipts.Count == 0, errorMessagePrefix);
        }
Example #12
0
        public async Task GetById_WithExistingId_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "UserService GetById() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);

            var expectedData = context.Users.First();
            var actualData   = await this.userService.GetById(expectedData.Id);

            Assert.True(expectedData.Id == actualData.Id, errorMessagePrefix + "Ids are different.");
            Assert.True(expectedData.FullName == actualData.FullName, errorMessagePrefix + "Full name is different.");
        }
        public async Task GetAllAuctionHouses_WithDummData_ShouldZeroResults()
        {
            string errorMessagePrefix = "ItemService GetAllItems does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            List <Item> actualResults = await
                                        this.itemService.GetAllItems().ToListAsync();

            Assert.True(actualResults.Count == 0, errorMessagePrefix);
        }
Example #14
0
        public async Task Delete_WithCorrectData_ShouldDeleteSuccessfullyCreate()
        {
            string errorMessagePrefix = "UserService Delete() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);

            var dummyUser      = context.Users.First();
            var dummyUsersItem = dummyUser.ItemsAuctioned.First().Name;

            bool actualResult = await this.userService.Delete(dummyUser.Id, dummyUsersItem);

            Assert.True(actualResult, errorMessagePrefix);
        }
Example #15
0
        public async Task CreateBid_WithCorrectParams_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "BidService CreateBid() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);
            this.bidService  = new BidService(context, userService);

            var dummyUserId = "Hugo";
            var dummyItem   = context.Items.First();
            var result      = await this.bidService.CreateBid(dummyItem, dummyUserId, 25);

            Assert.True(result, errorMessagePrefix);
        }
        public async Task ReceiptCreate_WithWrongMissingItemIdData_ShouldReturnNull()
        {
            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.receiptService = new ReceiptService(context);

            var dummyUser = new AuctionUser
            {
                FullName = "Pesho"
            };
            var dummyItemId = "Missing";

            context.Users.Add(dummyUser);

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.receiptService.CreateReceipt(dummyItemId, dummyUser.Id));
        }
Example #17
0
        public async Task CreateBid_WithIncorrectItem_ShouldReturnFaslse()
        {
            string errorMessagePrefix = "BidService CreateBid() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);
            this.bidService  = new BidService(context, userService);


            var dummyUserId = "Hugo";
            var dummyItem   = context.Items.FirstOrDefault(x => x.Name == "missing");
            var result      = await this.bidService.CreateBid(dummyItem, dummyUserId, 25);

            Assert.False(result, errorMessagePrefix);
        }
        public async Task GetById_WithExistingId_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "AuctionService GetById() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.auctionHouseService = new AuctionHouseService(context);

            var expectedData = context.AuctionHouses.First();
            var actualData   = await this.auctionHouseService.GetById(expectedData.Id);

            Assert.True(expectedData.Id == actualData.Id, errorMessagePrefix + "Ids are different.");
            Assert.True(expectedData.Address == actualData.Address, errorMessagePrefix + "Adresses are different.");
            Assert.True(expectedData.Description == actualData.Description, errorMessagePrefix + "Descriptions are different.");
            Assert.True(expectedData.City.Name == actualData.City.Name, errorMessagePrefix + "City names are different.");
        }
Example #19
0
        public async Task Edit_FullName_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "UserService Edit() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService = new UserService(context);

            var user = context.Users.First();

            var fullName = "Hugo";

            bool result = await this.userService.Edit(user.Id, fullName);

            Assert.True(result, errorMessagePrefix);
        }
        public async Task Create_WithNotExistingCity_ShouldReturnSuccessfullyCreate()
        {
            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.auctionHouseService = new AuctionHouseService(context);

            var testAuctionHouse = new AuctionHouseCreateInputModel
            {
                Name        = "Lucky",
                Address     = "Hope street",
                Description = "We belive",
                City        = "Yeet"
            };

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.auctionHouseService.Create(testAuctionHouse));
        }
        public async Task Delete_WithCorrectId_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "ItemService Delete() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var itemId = "SpoonId";

            bool actualResult = await this.itemService.Delete(itemId);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task Create_WithCorrectData_ShouldReturnSuccessfullyCreate()
        {
            string errorMessagePrefix = "CityService CreateCity() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.cityService = new CityService(context);

            var testAuctionHouse = new CityCreateInputModel
            {
                Name = "Sofia"
            };

            bool actualResult = await this.cityService.CreateCity(testAuctionHouse);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task GetReceiptsById_WithCorrectId_ShouldCorrectResults()
        {
            string errorMessagePrefix = "ReceiptService GetReceiptsById does not work properly.";
            string userId             = "Hugo";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.receiptService = new ReceiptService(context);

            var actualReceipts = await this.receiptService.GetReceiptsById(userId).ToListAsync();

            var expectedReceipts = GetDummyReceipts();

            for (int i = 0; i < expectedReceipts.Count; i++)
            {
                Assert.True(expectedReceipts[0].ItemId == actualReceipts[0].ItemId, errorMessagePrefix + "Item ids are different.");
                Assert.True(expectedReceipts[0].UserId == actualReceipts[0].UserId, errorMessagePrefix + "User ids are different.");
            }
        }
        public async Task Create_WithCorrectData_ShouldReturnSuccessfullyCreate()
        {
            string errorMessagePrefix = "AuctionService Create() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.auctionHouseService = new AuctionHouseService(context);

            var testAuctionHouse = new AuctionHouseCreateInputModel
            {
                Name        = "Lucky",
                Address     = "Hope street",
                Description = "We belive",
                City        = "Richmond"
            };

            bool actualResult = await this.auctionHouseService.Create(testAuctionHouse);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task CreateReview_WithCorrectData_ShouldReturnSuccessfullyCreate()
        {
            string errorMessagePrefix = "AuctionService CreateReview() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.auctionHouseService = new AuctionHouseService(context);

            var dummyAuctionId = context.AuctionHouses.First().Id;

            var reviewModel = new AuctionHouseReviewInputModel
            {
                Author      = "Hugo",
                Description = "Hugo is the best"
            };

            bool actualResult = await this.auctionHouseService.CreateReview(dummyAuctionId, reviewModel);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task ReceiptCreate_WithCorrectData_ShouldReturnSuccessfullyCreate()
        {
            string errorMessagePrefix = "ReceiptService ReceiptCreate() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.receiptService = new ReceiptService(context);

            var dummyUser = new AuctionUser
            {
                FullName = "Pesho"
            };
            var dummyItemId = context.Items.First().Id;

            context.Users.Add(dummyUser);

            bool actualResult = await this.receiptService.CreateReceipt(dummyItemId, dummyUser.Id);

            Assert.True(actualResult, errorMessagePrefix);
        }
        public async Task Buy_WithNonExcistantItemId_ShouldThrowException()
        {
            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var dummyItemId = "Missing";

            var dummyUser = new AuctionUser
            {
                Id = "Hugo"
            };

            context.Users.Add(dummyUser);

            await Assert.ThrowsAsync <ArgumentNullException>(() => this.itemService.Buy(dummyItemId, dummyUser.Id));
        }
        public async Task GetById_WithExistingId_ShouldReturnCorrectResult()
        {
            string errorMessagePrefix = "ItemService GetById() does not work properly.";

            var context = AuctionDbContextInMemory.InitializeContext();

            await SeedData(context);

            this.userService       = new UserService(context);
            this.receiptService    = new ReceiptService(context);
            this.cloudinaryService = new CloudinaryService(cloudinaryUtility);
            this.itemService       = new ItemService(context, cloudinaryService, userService, receiptService);

            var expectedData = context.Items.First();
            var actualData   = await this.itemService.GetById(expectedData.Id);

            Assert.True(actualData.Name == expectedData.Name, errorMessagePrefix + "Names are different.");
            Assert.True(actualData.StartingPrice == expectedData.StartingPrice, errorMessagePrefix + "Starting prices are different.");
            Assert.True(actualData.BuyOutPrice == expectedData.BuyOutPrice, errorMessagePrefix + "Buy out prices are different.");
            Assert.True(actualData.StartTime == expectedData.StartTime, errorMessagePrefix + "Start times are different.");
            Assert.True(actualData.EndTime == expectedData.EndTime, errorMessagePrefix + "End times are different.");
            Assert.True(actualData.Description == expectedData.Description, errorMessagePrefix + "Descriptions are different.");
        }