Esempio n. 1
0
        public async Task AddNotificationToDB_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(AddNotificationToDB_WithCorrectParameters));

            var adminName = "pesho";
            var id        = "1";
            var barName   = "newBar";

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetUsernameById(id))
            .ReturnsAsync(admin.UserName);
            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.BarAddedDescription(adminName, barName))
            .Returns($"New Bar notification: User: {adminName}, just added new Bar with name: {barName}");

            using (var arrangeContext = new CMContext(options))
            {
                arrangeContext.Add(admin);
                await arrangeContext.SaveChangesAsync();

                Assert.AreEqual(0, arrangeContext.Notifications.Count());
                var sut = new NotificationServices(arrangeContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                await sut.BarCreateNotificationToAdminAsync(id, barName);

                Assert.AreEqual(1, arrangeContext.Notifications.Count());
            }
        }
Esempio n. 2
0
        public async Task ThrowCorrectMessage_WhenPassedBarNameIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowCorrectMessage_WhenPassedBarNameIsNull));

            var adminName = "pesho";
            var id        = "1";
            var barName   = "newBar";

            var admin = new AppUser
            {
                Id       = id,
                UserName = adminName
            };

            _userServices.Setup(x => x.GetUsernameById(id))
            .ReturnsAsync(admin.UserName);
            _userServices.Setup(x => x.GetAdmin())
            .ReturnsAsync(admin);
            _iNotificationManager.Setup(x => x.BarAddedDescription(adminName, barName))
            .Returns($"New Bar notification: User: {adminName}, just added new Bar with name: {barName}");
            using (var assertContext = new CMContext(options))
            {
                var sut = new NotificationServices(assertContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.BarCreateNotificationToAdminAsync(id, null));

                Assert.AreEqual(ExceptionMessages.BarNameNull, ex.Message);
            }
        }