Пример #1
0
        public async Task AddNotificationToDBForCreateCocktail_WithCorrectParameters()
        {
            var options = TestUtils.GetOptions(nameof(AddNotificationToDBForCreateCocktail_WithCorrectParameters));

            var adminName    = "pesho";
            var id           = "1";
            var cocktailName = "newCocktail";

            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.CocktailAddedDescription(adminName, cocktailName))
            .Returns("LALALALALA");

            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.CocktailCreateNotificationToAdminAsync(id, cocktailName);

                Assert.AreEqual(1, arrangeContext.Notifications.Count());
            }
        }
Пример #2
0
        public async Task ThrowCorrectMessage_WhenPassedCocktailNameIsNull()
        {
            var options = TestUtils.GetOptions(nameof(ThrowCorrectMessage_WhenPassedCocktailNameIsNull));

            var adminName    = "pesho";
            var id           = "1";
            var cocktailName = "new";

            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.CocktailAddedDescription(adminName, cocktailName))
            .Returns($"LALALALA");
            using (var assertContext = new CMContext(options))
            {
                var sut = new NotificationServices(assertContext, _userServices.Object,
                                                   _iNotificationManager.Object);
                var ex = await Assert.ThrowsExceptionAsync <MagicException>(
                    async() => await sut.CocktailCreateNotificationToAdminAsync(id, null));

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