Exemplo n.º 1
0
        public async Task ReturnUser_WhenValidIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnUser_WhenValidIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User()
            {
                UserName = "******"
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.UserService(bedeSlotsContext,
                                               userManager);

                var result = await sut.GetUserByIdAsync(user.Id);

                Assert.IsTrue(result != null);
            }
        }
Exemplo n.º 2
0
        public async Task ThrowServiceException_WhenNullParameterIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenNullParameterIsPassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.UserService(bedeSlotsContext,
                                               userManager);

                await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.GetUserByIdAsync(null));
            }
        }