Ejemplo n.º 1
0
        public void SetupTest()
        {
            LoggerMock = new Mock <ILogger <MessageService> >();

            var options = new DbContextOptionsBuilder <GametekiDbContext>()
                          .UseInMemoryDatabase(databaseName: "MessageServiceTests")
                          .Options;

            DbContext = new GametekiDbContext(options);

            for (var i = 0; i < 500; i++)
            {
                var message = TestUtils.GetRandomLobbyMessage();

                if (i % 2 == 0)
                {
                    message.Removed         = true;
                    message.RemovedById     = Guid.NewGuid().ToString();
                    message.RemovedDateTime = DateTime.UtcNow;
                }

                DbContext.LobbyMessage.Add(message);
                DbContext.SaveChangesAsync().GetAwaiter().GetResult();
            }

            Service = new MessageService(DbContext, LoggerMock.Object);
        }
Ejemplo n.º 2
0
        public async Task SetupTest()
        {
            var options = new DbContextOptionsBuilder <GametekiDbContext>()
                          .UseInMemoryDatabase(databaseName: "UserServiceTests")
                          .Options;

            DbContext = new GametekiDbContext(options);

            await DbContext.Database.EnsureDeletedAsync();

            UserStoreMock         = new Mock <IUserStore <GametekiUser> >();
            UserManagerMock       = new Mock <UserManager <GametekiUser> >(UserStoreMock.Object, null, null, null, null, null, null, null, null);
            AuthTokenOptionsMock  = new Mock <IOptions <AuthTokenOptions> >();
            GametekiOptionsMock   = new Mock <IOptions <GametekiApiOptions> >();
            EmailSenderMock       = new Mock <IEmailSender>();
            ViewRenderServiceMock = new Mock <IViewRenderService>();
            LoggerMock            = new Mock <ILogger <UserService> >();

            AuthTokenOptionsMock.Setup(at => at.Value).Returns(new AuthTokenOptions
            {
                Issuer = "http://test.com",
                Key    = "really super awesome key of testing"
            });
            GametekiOptionsMock.Setup(lo => lo.Value).Returns(new GametekiApiOptions {
                ApplicationName = "TestApp"
            });

            TestUsers = new List <GametekiUser>();
            for (var i = 0; i < 10; i++)
            {
                TestUsers.Add(TestUtils.GetRandomUser());
            }

            var roles = new[] { new GametekiRole(Roles.GameManager), new GametekiRole(Roles.NewsManager), new GametekiRole(Roles.UserManager) };

            DbContext.Roles.AddRange(roles);

            DbContext.Users.AddRange(TestUsers);
            await DbContext.SaveChangesAsync();

            Service = new UserService(
                DbContext,
                UserManagerMock.Object,
                AuthTokenOptionsMock.Object,
                GametekiOptionsMock.Object,
                EmailSenderMock.Object,
                ViewRenderServiceMock.Object,
                LoggerMock.Object);
        }
Ejemplo n.º 3
0
        public async Task SetupTest()
        {
            var options = new DbContextOptionsBuilder <GametekiDbContext>()
                          .UseInMemoryDatabase(databaseName: "NewsServiceTests")
                          .Options;

            DbContext = new GametekiDbContext(options);

            NewsItems = new List <News>();

            for (var i = 0; i < 10; i++)
            {
                NewsItems.Add(TestUtils.GetRandomNews());
            }

            await DbContext.News.AddRangeAsync(NewsItems);

            await DbContext.SaveChangesAsync();

            MockLogger = new Mock <ILogger <NewsService> >();

            Service = new NewsService(DbContext, MockLogger.Object);
        }