Пример #1
0
        public void ShouldReturnInstanceOfIQueryable()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <SelfEmployment> >();

            var selfEmplService = new SelfEmploymentService(mockedRepository.Object);

            SelfEmployment mockedSelfEmpl  = new  FakeSelfEmployment();
            SelfEmployment mockedSelfEmpl2 = new FakeSelfEmployment();
            SelfEmployment mockedSelfEmpl3 = new FakeSelfEmployment();

            mockedSelfEmpl.Id  = 2;
            mockedSelfEmpl2.Id = 3;
            mockedSelfEmpl3.Id = 4;

            // Act
            selfEmplService.Create(mockedSelfEmpl);
            selfEmplService.Create(mockedSelfEmpl2);
            selfEmplService.Create(mockedSelfEmpl3);

            var query = selfEmplService.GetTop(3);

            // Assert
            Assert.IsInstanceOf <IQueryable <SelfEmployment> >(query);
        }
Пример #2
0
        public void ShouldInvokeOnceAndUpdateBill()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <SelfEmployment> >();

            var selfEmplService = new SelfEmploymentService(mockedRepository.Object);

            SelfEmployment mockedSelfEmpl  = new FakeSelfEmployment();
            SelfEmployment mockedSelfEmpl2 = new FakeSelfEmployment();
            SelfEmployment mockedSelfEmpl3 = new FakeSelfEmployment();

            mockedSelfEmpl.Id  = 2;
            mockedSelfEmpl2.Id = 3;
            mockedSelfEmpl3.Id = 4;

            // Act
            selfEmplService.Create(mockedSelfEmpl);
            selfEmplService.Create(mockedSelfEmpl2);
            selfEmplService.Create(mockedSelfEmpl3);

            selfEmplService.UpdateById(2, mockedSelfEmpl);

            // Assert
            mockedRepository.Verify(r => r.Update(mockedSelfEmpl), Times.Once);
        }
Пример #3
0
        public void ShouldInvokeOnlyOnce_WhenIsCalled()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <SelfEmployment> >();

            var selfEmplService = new SelfEmploymentService(mockedRepository.Object);

            SelfEmployment mockedSelfEmpl  = new FakeSelfEmployment();
            SelfEmployment mockedSelfEmpl2 = new FakeSelfEmployment();
            SelfEmployment mockedSelfEmpl3 = new FakeSelfEmployment();

            mockedSelfEmpl.Id  = 2;
            mockedSelfEmpl2.Id = 3;
            mockedSelfEmpl3.Id = 4;

            // Act
            selfEmplService.Create(mockedSelfEmpl);
            selfEmplService.Create(mockedSelfEmpl2);
            selfEmplService.Create(mockedSelfEmpl3);

            selfEmplService.GetTop(3);

            // Assert
            mockedRepository.Verify(r => r.All, Times.Once);
        }
Пример #4
0
        public void ThrowArgumentNullException_WhenParameterIsNull()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <SelfEmployment> >();

            var selfEmplService = new SelfEmploymentService(mockedRepository.Object);

            // Act & Assert
            Assert.That(() => selfEmplService.Create(null), Throws.InstanceOf <ArgumentNullException>().With.Message.Contains("The argument is null"));
        }
Пример #5
0
        public void InvokeOnce_WhenParameterIsCorrect()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <SelfEmployment> >();

            var selfEmplService = new SelfEmploymentService(mockedRepository.Object);

            var mockedSelfEmployment = new FakeSelfEmployment();

            // Act
            selfEmplService.Create(mockedSelfEmployment);

            // Assert
            mockedRepository.Verify(r => r.Add(mockedSelfEmployment), Times.Once);
        }
Пример #6
0
        public void InvokeOnce_WhenValidId_IsPassedCorrectly()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <SelfEmployment> >();

            var selfEmplService = new SelfEmploymentService(mockedRepository.Object);

            SelfEmployment bill = new FakeSelfEmployment();

            bill.Id = 2;

            // Act
            selfEmplService.Create(bill);
            selfEmplService.DeleteById(2);

            // Assert
            mockedRepository.Verify(r => r.Delete(It.IsAny <int>()), Times.Once);
        }
Пример #7
0
        public void GetById_ShouldInvokeOnlyOnce()
        {
            // Arrange
            var mockedRepository = new Mock <IRepository <SelfEmployment> >();

            var selfEmplService = new SelfEmploymentService(mockedRepository.Object);

            var mockedSelfEmployment = new FakeSelfEmployment();

            mockedSelfEmployment.Id = 2;

            // Act
            selfEmplService.Create(mockedSelfEmployment);

            selfEmplService.GetById(mockedSelfEmployment.Id);

            // Assert
            mockedRepository.Verify(r => r.GetById(mockedSelfEmployment.Id), Times.Once);
        }