public async Task Should_AddModeratorToBusinessUnitsAsync()
        {
            var options = TestUtils.GetOptions(nameof(Should_AddModeratorToBusinessUnitsAsync));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.Users.AddAsync(TestHelperBusinessUnit.TestUser01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>(MockBehavior.Strict);

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnitDTO = await sut.AddModeratorToBusinessUnitsAsync(TestHelperBusinessUnit.TestUser01().Id, TestHelperBusinessUnit.TestBusinessUnit01().Id);

                var moderatorUser = await assertContext.Users.FindAsync(TestHelperBusinessUnit.TestUser01().Id);

                Assert.AreEqual(moderatorUser.BusinessUnitId, TestHelperBusinessUnit.TestBusinessUnit01().Id);
            }
        }
        public async Task ThrowsExceptionWhenBusinessUnitCategoryNameAlreadyExists()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExceptionWhenBusinessUnitCategoryNameAlreadyExists));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit02());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var ex = await Assert.ThrowsExceptionAsync <AlreadyExistsException>(() => sut.CreateBusinessUnitCategoryAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01().Name));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.BusinessUnitCategoryNameAlreadyExists));
            }
        }
        public async Task ThrowsExceptionWhenModeratorUserDoesExists_AddModeratorToBusinessUnitsAsync()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExceptionWhenModeratorUserDoesExists_AddModeratorToBusinessUnitsAsync));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.Users.AddAsync(TestHelperBusinessUnit.TestUser01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>(MockBehavior.Strict);

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnit = await sut.AddModeratorToBusinessUnitsAsync(TestHelperBusinessUnit.TestUser01().Id, TestHelperBusinessUnit.TestBusinessUnit01().Id);

                var moderatorUser = await assertContext.Users.FindAsync(TestHelperBusinessUnit.TestUser01().Id);

                var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.AddModeratorToBusinessUnitsAsync("11", TestHelperBusinessUnit.TestBusinessUnit01().Id));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserNotFound));
            }
        }
Esempio n. 4
0
        public async Task ThrowsException_UpdateBusinessUnitNameAlreadyExists()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsException_UpdateBusinessUnitNameAlreadyExists));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit02());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var ex = await Assert.ThrowsExceptionAsync <AlreadyExistsException>(() => sut.UpdateBusinessUnitAsync(1, TestHelperBusinessUnit.TestBusinessUnit02().Name, "Nishava 12", "1234567890", "information2", "*****@*****.**", 1, 1, "picture2"));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.BusinessUnitNameAlreadyExists));
            }
        }
        public async Task Succeed_ReturnGetBusinessUnitById()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnGetBusinessUnitById));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var getBusinessUnitById = await sut.GetBusinessUnitById(1);

                Assert.AreEqual(getBusinessUnitById.Id, 1);
            }
        }
        public async Task Succeed_ReturnCreateBusinessUnit()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnCreateBusinessUnit));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnitDTO = await sut.CreateBusinnesUnitAsync("Hilton", "Cerni Vryh 15", "0123456789", "*****@*****.**", "Information for BU", 1, 1, "picture");

                mockBusinessValidator.Verify(x => x.IsNameInRange("Hilton"), Times.Exactly(1));
                mockBusinessValidator.Verify(x => x.IsAddressInRange("Cerni Vryh 15"), Times.Exactly(1));
                mockBusinessValidator.Verify(x => x.IsPhoneNumberValid("0123456789"), Times.Exactly(1));
                mockBusinessValidator.Verify(x => x.IsEmailValid("*****@*****.**"), Times.Exactly(1));

                Assert.AreEqual(businessUnitDTO.Name, "Hilton");
                Assert.AreEqual(businessUnitDTO.Address, "Cerni Vryh 15");
                Assert.AreEqual(businessUnitDTO.PhoneNumber, "0123456789");
                Assert.AreEqual(businessUnitDTO.Email, "*****@*****.**");
            }
        }
        public async Task GiveLikeBusinessUnitAsync()
        {
            var options = TestUtils.GetOptions(nameof(GiveLikeBusinessUnitAsync));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>(MockBehavior.Strict);

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnitDTO = await sut.GiveLikeBusinessUnitAsync(TestHelperBusinessUnit.TestBusinessUnit01().Id);

                Assert.AreEqual(businessUnitDTO.Likes, 1);
            }
        }
        public async Task Should_GetAllBusinessUnitsByBusinessUnitCategoryAsync()
        {
            var options = TestUtils.GetOptions(nameof(Should_GetAllBusinessUnitsByBusinessUnitCategoryAsync));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit02());

                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>(MockBehavior.Strict);

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnits = await sut.GetAllBusinessUnitsByCategoryIdAsync(1);

                Assert.AreEqual(businessUnits.Count, 2);
            }
        }
Esempio n. 9
0
        public async Task Should_SearchBusinessUnitsWhenTownIsNullAsync()
        {
            var options = TestUtils.GetOptions(nameof(Should_SearchBusinessUnitsWhenTownIsNullAsync));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit02());

                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>(MockBehavior.Strict);
                var mockListBusinessUnit  = new List <BusinessUnit>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnits = await sut.SearchBusinessUnitsAsync("Kempinski", 1, null);

                Assert.AreEqual(businessUnits.Count, 1);
            }
        }
        public async Task ThrowsException_GetLogbooksForBusinessUnitNotFound()
        {
            var options = TestUtils.GetOptions(nameof(Should_GetAllLogbooksForBusinessUnitAsync));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.Logbooks.AddAsync(TestHelperBusinessUnit.TestLogbook02());

                await arrangeContext.Logbooks.AddAsync(TestHelperBusinessUnit.TestLogbook03());

                await arrangeContext.Notes.AddAsync(TestHelperBusinessUnit.TestNote01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>(MockBehavior.Strict);

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.GetAllLogbooksForBusinessUnitAsync(2));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.BusinessUnitNotFound));
            }
        }
        public async Task Succeed_ReturnCreateBusinessUnitCategory()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnCreateBusinessUnitCategory));

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnitCategoryDTO = await sut.CreateBusinessUnitCategoryAsync("Restaurant");

                mockBusinessValidator.Verify(x => x.IsNameInRange("Restaurant"), Times.Exactly(1));

                Assert.AreEqual(businessUnitCategoryDTO.Name, "Restaurant");
            }
        }
Esempio n. 12
0
        public async Task Succeed_UpdateBusinessUnit()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_UpdateBusinessUnit));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.Towns.AddAsync(TestHelperBusinessUnit.TestTown01());

                await arrangeContext.BusinessUnits.AddAsync(TestHelperBusinessUnit.TestBusinessUnit01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnit = await sut.UpdateBusinessUnitAsync(TestHelperBusinessUnit.TestBusinessUnit01().Id, "Vitosha", "Cerni Vryh 25", "9876543210", "This is information for BU", "*****@*****.**", 1, 1, "picturePath");

                mockBusinessValidator.Verify(x => x.IsNameInRange("Vitosha"), Times.Exactly(1));
                mockBusinessValidator.Verify(x => x.IsAddressInRange("Cerni Vryh 25"), Times.Exactly(1));
                mockBusinessValidator.Verify(x => x.IsPhoneNumberValid("9876543210"), Times.Exactly(1));
                mockBusinessValidator.Verify(x => x.IsDescriptionInRange("This is information for BU"), Times.Exactly(1));
                mockBusinessValidator.Verify(x => x.IsEmailValid("*****@*****.**"), Times.Exactly(1));

                Assert.AreEqual(businessUnit.Name, "Vitosha");
                Assert.AreEqual(businessUnit.Address, "Cerni Vryh 25");
                Assert.AreEqual(businessUnit.PhoneNumber, "9876543210");
                Assert.AreEqual(businessUnit.Information, "This is information for BU");
                Assert.AreEqual(businessUnit.Email, "*****@*****.**");
                Assert.AreEqual(businessUnit.Picture, "picturePath");
            }
        }
Esempio n. 13
0
        public async Task Succeed_UpdateBusinessUnitCategoryName()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_UpdateBusinessUnitCategoryName));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnitCategories.AddAsync(TestHelperBusinessUnit.TestBusinessUnitCategory01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();

                var sut = new BusinessUnitService(assertContext, mockBusinessValidator.Object);

                var businessUnitCategoryDTO = await sut.UpdateBusinessUnitCategoryAsync(1, "Hostel");

                mockBusinessValidator.Verify(x => x.IsNameInRange("Hostel"), Times.Exactly(1));

                Assert.AreEqual(businessUnitCategoryDTO.Name, "Hostel");
            }
        }