Beispiel #1
0
        public async void CorrectNumberOfGummyBearsForUsersRoleIsReturned(string roleName, int expectedNumberOfGummyBearsReturned)
        {
            // Arrange
            const string SWEET_TOOTH_ROLENAME = "SweetTooth";

            var userId = Guid.NewGuid().ToString();

            var mockUserStore     = new Mock <IUserStore <ApplicationUser> >();
            var mockUserRoleStore = mockUserStore.As <IUserRoleStore <ApplicationUser> >();
            var userManager       = new UserManager <ApplicationUser>(mockUserStore.Object);

            mockUserStore.Setup(x => x.FindByIdAsync(userId))
            .ReturnsAsync(new ApplicationUser()
            {
                UserName = "******"
            });

            mockUserRoleStore.Setup(x => x.IsInRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(roleName.Equals(SWEET_TOOTH_ROLENAME, StringComparison.OrdinalIgnoreCase));

            var objectUnderTest = new SweetService(userManager);

            // Act
            var actualResult = await objectUnderTest.NumberOfGummyBearsForUser(userId);

            // Assert
            Assert.Equal(expectedNumberOfGummyBearsReturned, actualResult);
        }
Beispiel #2
0
 public SweetController()
 {
     _service = new SweetService(new SweetLifeDbContext());
 }