Example #1
0
        public void TestGetAllPcParts()
        {
            // Arrange
            var repo = new PcPartRepository(_context, _mapper);

            // act
            var result = repo.GetAll();

            // assert
            Assert.Equal(34, result.Count());
        }
Example #2
0
        public async Task TestPcPartsGetById()
        {
            // arrange
            var repo = new PcPartRepository(_context, _mapper);

            // act
            var result = await repo.GetById(1);

            // assert
            Assert.Equal(MockData.StandardPcPart.Name, result.Name);
        }
Example #3
0
        public async void TestPcPartForListBasic()
        {
            // arrange
            var repo = new PcPartRepository(_context, _mapper);
            // expected

            // act
            var result = await repo.GetPartsBasic();

            // assert
            Assert.Equal(MockData.ListOfPcParts.Count(), result.Count());
        }
Example #4
0
        public async void TestPcPartUpdatePcPart()
        {
            // arrange
            var repo = new PcPartRepository(_context, _mapper);
            // expected
            var expectedPartName = MockData.StandardPcPart.Name;

            // act
            var result = await repo.Update(await repo.GetById(1));

            // assert
            Assert.Equal(expectedPartName, result.Name);
        }
Example #5
0
        public async void TestPcPartForBasicPart()
        {
            // arrange
            var repo = new PcPartRepository(_context, _mapper);
            // expected
            string expectedPartName = MockData.StandardPcPart.Name;

            // act
            var result = await repo.GetPartsBasicById(1);

            // assert
            Assert.Equal(expectedPartName, result.Name);
        }
Example #6
0
        public void TestPcPartRepoForImageByName()
        {
            // arrange
            var repo = new PcPartRepository(_context, _mapper);
            // expected
            var image = MockData.ListOfImages.Where(i => i.FileName == "amd_ryzen_5.jpg").FirstOrDefault();

            // act
            var result = repo.GetImagePathByName("amd_ryzen_5.jpg");

            // assert
            Assert.Equal(image.Id, result.Id);
        }
Example #7
0
        public async Task TestPcPartRepoGetPartByPcPartId()
        {
            // arrange
            var repo      = new PcPartRepository(_context, _mapper);
            int partIndex = 5;
            var expected  = MockData.Cpus.Where(c => c.Id == 2).FirstOrDefault(); // 2 is the cpu with partId 5

            // act
            var result = await repo.GetPartById(partIndex);

            // assert
            Assert.Equal(expected.PcPartId, result.PcPartId);
        }
Example #8
0
        public async Task TestGetAllByCategoryNamePCpartsRepo()
        {
            // arrange
            var repo = new PcPartRepository(_context, _mapper);
            // expected
            var parts = repo.db.PcParts.Where(p => p.Type == PartType.Gpu).ToList();

            // act
            var result = await repo.GetAllByCategoryName("Gpu");

            // assert
            Assert.Equal(parts, result);
        }
Example #9
0
        public async void TestPcPartControllerGetPartByPcPartId()
        {
            // arrange
            var repo       = new PcPartRepository(_context, _mapper);
            var controller = new PcPartsController(repo);

            // act
            var result = await controller.PartByPartId(4);

            // assert
            var objectResult = Assert.IsType <OkObjectResult>(result);

            Assert.Equal(StatusCodes.Status200OK, objectResult.StatusCode);
        }
Example #10
0
        public void TestPcPartControllerGetCategories()
        {
            // arrange
            var repo       = new PcPartRepository(_context, _mapper);
            var controller = new PcPartsController(repo);

            // act
            var result = controller.Categories();

            // assert
            var objectResult = Assert.IsType <OkObjectResult>(result);

            Assert.Equal(StatusCodes.Status200OK, objectResult.StatusCode);
        }
Example #11
0
        public async void TestPcPartAddPcPart()
        {
            // arrange
            var repo = new PcPartRepository(_context, _mapper);
            // expected
            var PartToAdd = await repo.GetById(1);

            PartToAdd.Name = "GeForce GTX 2090 Ti";

            // act
            var result = await repo.Add(PartToAdd);

            // assert
            Assert.Equal(PartToAdd.Name, result.Name);
        }
Example #12
0
        public async void TestPcPartControllerImageByFileName()
        {
            // arrange
            var repo        = new PcPartRepository(_context, _mapper);
            var controller  = new PcPartsController(repo);
            var contentType = "image/jpeg";


            // act
            var result = controller.ImageByFileName("amd_ryzen_5.jpg");

            // assert
            var objectResult = Assert.IsType <PhysicalFileResult>(result);

            Assert.Equal(contentType, objectResult.ContentType);
        }