Example #1
0
        public void UpdateBike_Updates_Bike()
        {
            var testId = 1;
            var bike   = new BikeEntity();
            var dto    = new BikeDto
            {
                Id          = Guid.NewGuid(),
                BikeModelId = Guid.NewGuid(),
                BikeColorId = testId,
                WheelSizeId = testId,
            };
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            bikeService.UpdateBike(dto);

            mockRepo.Verify(r => r.Update(
                                It.Is <BikeEntity>(b =>
                                                   b.IsActive == true &&
                                                   b.BikeColorId == dto.BikeColorId &&
                                                   b.BikeModelId == dto.BikeModelId &&
                                                   b.WheelSizeId == dto.WheelSizeId &&
                                                   b.PurchaseDate.Date == DateTime.UtcNow.Date &&
                                                   b.RemovedFromInventoryDate == null)),
                            Times.Once);
        }
        public BikeHistoryItemDto CreateHistoryItem(BikeHistoryItemDto historyItemDto)
        {
            var historyItemToReturn = _mapper.Map <BikeHistoryItemEntity>(historyItemDto);
            var historyItem         = _bikeHistoryRepository.Insert(historyItemToReturn);

            return(_mapper.Map <BikeHistoryItemDto>(historyItem));
        }
        public void CreateHistoryItem_Calls_Create_In_Repo()
        {
            var dto = new BikeHistoryItemDto();

            bikeHistoryService.CreateHistoryItem(dto);
            mockRepo.Verify(r => r.Insert
                                (It.IsAny <BikeHistoryItemEntity>()), Times.Once);
        }
        public void UpdateHistoryItem(BikeHistoryItemDto historyItemDto)
        {
            var historyItem = _bikeHistoryRepository.GetById(historyItemDto.Id);

            historyItem.BikeId             = historyItemDto.BikeId;
            historyItem.StatusId           = historyItemDto.StatusId;
            historyItem.DateTimeLastEdited = DateTime.UtcNow;

            _bikeHistoryRepository.Update(historyItem);
        }
        public void CreateHistoryItem_Inserts_BikeHistoryItem()
        {
            var entity = new BikeHistoryItemEntity();
            var dto    = new BikeHistoryItemDto();

            mockMapper.Setup(m => m.Map <BikeHistoryItemEntity>(dto)).Returns(entity);
            bikeHistoryService.CreateHistoryItem(dto);

            mockRepo.Verify(r => r.Insert(entity), Times.Once);
        }
Example #6
0
        private Guid CreateHistoryItemForBike(Guid bikeId, Status status)
        {
            var hisotryItemDto = new BikeHistoryItemDto
            {
                BikeId   = bikeId,
                StatusId = (int)status
            };

            return(_historyService.CreateHistoryItem(hisotryItemDto).Id);
        }
        public void CreateHistoryItem_Returns_BikeHistoryItemDto()
        {
            var entity = new BikeHistoryItemEntity();
            var dto    = new BikeHistoryItemDto();

            mockRepo.Setup(r => r.Insert(It.IsAny <BikeHistoryItemEntity>()))
            .Returns(entity);

            mockMapper.Setup(m => m.Map <BikeHistoryItemDto>(entity)).Returns(dto);
            var actual = bikeHistoryService.CreateHistoryItem(dto);

            Assert.AreEqual(dto, actual);
        }
Example #8
0
        public void CreateNewBike_Calls_CreateHistoryItem_In_BikeHistoryService()
        {
            var entity      = new BikeEntity();
            var dto         = new BikeDto();
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.Insert(It.IsAny <BikeEntity>())).Returns(entity);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            bikeService.CreateNewBike(dto);

            mockHistoryService.Verify(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>()), Times.Once);
        }
Example #9
0
        public void CreateNewBike_Returns_BikeDto()
        {
            var entity      = new BikeEntity();
            var dto         = new BikeDto();
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.Insert(It.IsAny <BikeEntity>())).Returns(entity);
            mockMapper.Setup(m => m.Map <BikeDto>(entity)).Returns(dto);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            var actual = bikeService.CreateNewBike(dto);

            Assert.AreEqual(dto, actual);
        }
        public void GetHistoryItemById_Returns_BikeHistoryItemDto()
        {
            var id     = Guid.NewGuid();
            var entity = new BikeHistoryItemEntity();
            var dto    = new BikeHistoryItemDto();

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>()))
            .Returns(entity);

            mockMapper.Setup(m => m.Map <BikeHistoryItemDto>(entity))
            .Returns(dto);

            BikeHistoryItemDto actual = bikeHistoryService.GetHistoryItemById(id);

            Assert.AreEqual(dto, actual);
        }
Example #11
0
        public void RemoveBike_Calls_CreateHistoryItem_In_BikeHistoryItemService()
        {
            var testStatus = Status.Fixed;
            var bike       = new BikeEntity();
            var dto        = new BikeDto
            {
                Id = Guid.NewGuid()
            };
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            bikeService.RemoveBike(dto.Id, testStatus);

            mockHistoryService.Verify(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>()), Times.Once);
        }
Example #12
0
        public void ChangeStatus_Calls_Update_In_Repo()
        {
            var testStatus = Status.Fixed;
            var bike       = new BikeEntity();
            var dto        = new BikeDto
            {
                Id = Guid.NewGuid(),
            };
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            bikeService.ChangeStatus(dto.Id, testStatus);

            mockRepo.Verify(r => r.Update(It.IsAny <BikeEntity>()), Times.Once);
        }
        public void UpdateHistoryItem_Calls_Create_In_Repo()
        {
            var testDesc = "test";
            var testId   = 1;
            var entity   = new BikeHistoryItemEntity();
            var dto      = new BikeHistoryItemDto
            {
                BikeId   = Guid.NewGuid(),
                StatusId = testId,
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>()))
            .Returns(entity);

            bikeHistoryService.UpdateHistoryItem(dto);

            mockRepo.Verify(r => r.Update
                                (It.IsAny <BikeHistoryItemEntity>()), Times.Once);
        }
        public void UpdateHistoryItem_Updates_BikeHistoryItemDto()
        {
            var testDesc = "test";
            var testId   = 1;
            var entity   = new BikeHistoryItemEntity();
            var dto      = new BikeHistoryItemDto
            {
                BikeId   = Guid.NewGuid(),
                StatusId = testId,
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>()))
            .Returns(entity);
            bikeHistoryService.UpdateHistoryItem(dto);

            mockRepo.Verify(r => r.Update(
                                It.Is <BikeHistoryItemEntity>(b =>
                                                              b.DateTimeLastEdited.Date == DateTime.UtcNow.Date)),
                            Times.Once);
        }
Example #15
0
        public void RemoveBike_Updates_Bike()
        {
            var testStatus = Status.Fixed;
            var bike       = new BikeEntity();
            var dto        = new BikeDto
            {
                Id = Guid.NewGuid()
            };
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            bikeService.RemoveBike(dto.Id, testStatus);

            mockRepo.Verify(r => r.Delete(
                                It.Is <BikeEntity>(b =>
                                                   b.CurrentStatusId == (int)testStatus)),
                            Times.Once);
        }
Example #16
0
        public void UpdateBike_Calls_CompareObjectProperties_In_ObjectInspectionService()
        {
            var testId = 1;
            var bike   = new BikeEntity();
            var dto    = new BikeDto
            {
                Id          = Guid.NewGuid(),
                BikeModelId = Guid.NewGuid(),
                BikeColorId = testId,
                WheelSizeId = testId,
            };
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            bikeService.UpdateBike(dto);

            mockInspectionService.Verify(r => r.GetDifferentPropertyValues(It.IsAny <BikeEntity>(), It.IsAny <BikeDto>(), It.IsAny <List <string> >()), Times.Once);
        }
Example #17
0
        public void UpdateBike_Calls_CreateHistoryItem_In_HistoryService()
        {
            var testId = 1;
            var bike   = new BikeEntity();
            var dto    = new BikeDto
            {
                Id          = Guid.NewGuid(),
                BikeModelId = Guid.NewGuid(),
                BikeColorId = testId,
                WheelSizeId = testId,
            };
            var historyItem = new BikeHistoryItemDto {
                Id = Guid.NewGuid()
            };

            mockRepo.Setup(r => r.GetById(It.IsAny <Guid>())).Returns(bike);
            mockHistoryService.Setup(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>())).Returns(historyItem);
            bikeService.UpdateBike(dto);

            mockHistoryService.Verify(r => r.CreateHistoryItem(It.IsAny <BikeHistoryItemDto>()), Times.Once);
        }