public static async Task Test_Controller_Produces_AlreadyHasActiveSession_When_Session_Has()
        {
            //arrange
            IServiceProvider            serviceProvider = ControllerTestsHelpers.BuildServiceProvider <CharacterSessionController>("Test", 1);
            CharacterSessionController  controller      = serviceProvider.GetService <CharacterSessionController>();
            ICharacterRepository        characterRepo   = serviceProvider.GetService <ICharacterRepository>();
            ICharacterSessionRepository sessionRepo     = serviceProvider.GetService <ICharacterSessionRepository>();

            await characterRepo.TryCreateAsync(new CharacterEntryModel(1, "Testing"));

            await sessionRepo.TryCreateAsync(new CharacterSessionModel(1, 0));

            //We can't create the claimed session through this interface because it's a stored procedure.
            //Raw SQL can't execute. So we must interact directly with the DbSet
            //await sessionRepo.TryClaimUnclaimedSession(1, 1);
            CharacterDatabaseContext context = serviceProvider.GetService <CharacterDatabaseContext>();
            await context.ClaimedSession.AddAsync(new ClaimedSessionsModel(1));

            await context.SaveChangesAsync();

            //act
            CharacterSessionEnterResponse response = await controller.EnterSession(1);

            //assert
            Assert.False(response.isSuccessful, $"Characters that already have ");
            Assert.AreEqual(CharacterSessionEnterResponseCode.AccountAlreadyHasCharacterSession, response.ResultCode);
        }
        public static void Test_MockedDatabaseContext_Can_Build()
        {
            //arange
            ServiceCollection collection = new ServiceCollection();

            IServiceProvider provider = collection.AddTestDatabaseContext <CharacterDatabaseContext>()
                                        .AddDefaultDataTestServices()
                                        .BuildServiceProvider();

            //act
            CharacterDatabaseContext result = provider.GetService <CharacterDatabaseContext>();

            //assert
            Assert.NotNull(result);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public DatabaseBackedCharacterFriendsRepository([JetBrains.Annotations.NotNull] CharacterDatabaseContext context)
        {
            Context = context ?? throw new ArgumentNullException(nameof(context));

            GenericRepository = new GeneralGenericCrudRepositoryProvider <int, CharacterFriendRelationshipModel>(context.CharacterFriendRequests, context);
        }
Ejemplo n.º 4
0
 public DatabaseBackedGuildCharacterMembershipRepository(CharacterDatabaseContext context)
 {
     GenericGuildRelationshipRepository = new GeneralGenericCrudRepositoryProvider <int, CharacterGuildMemberRelationshipModel>(context.GuildMembers, context);
 }
 /// <inheritdoc />
 public DatabaseBackedGroupEntryRepository([JetBrains.Annotations.NotNull] CharacterDatabaseContext context)
 {
     Context = context ?? throw new ArgumentNullException(nameof(context));
     GenericBackedRepository = new GeneralGenericCrudRepositoryProvider <int, CharacterGroupEntryModel>(context.Groups, context);
 }
 /// <inheritdoc />
 public DatabaseBackedCharacterLocationRepository(CharacterDatabaseContext context)
 {
     Context = context ?? throw new ArgumentNullException(nameof(context));
 }
 /// <inheritdoc />
 public DatabaseBackedCharacterSessionRepository(CharacterDatabaseContext context)
 {
     Context            = context ?? throw new ArgumentNullException(nameof(context));
     GenericCrudService = new GeneralGenericCrudRepositoryProvider <int, CharacterSessionModel>(context.CharacterSessions, context);
 }