Beispiel #1
0
        public async Task RegisterCharacter_Should_Throw_If_No_Dungeon_Found()
        {
            using (var context = await GetDatabase())
            {
                var mapper           = this.GetMapper();
                var characterService = new CharacterService(context, mapper);
                var dungeonService   = new DungeonService(context, characterService, mapper);

                await Assert.ThrowsAsync <InvalidOperationException>(async() => await dungeonService.RegisterCharacterAsync("IncorectId", "1"));
            }
        }
Beispiel #2
0
        public async Task GetDestinationId_Should_Return_Correct_Id()
        {
            using var context = await GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var dungeonService   = new DungeonService(context, characterService, mapper);

            var expected = "1";
            var actual   = dungeonService.GetDestinationId("TestDest");

            Assert.Equal(expected, actual);
        }
        public void GetDungeon_ExistingDungeonNumber_ReturnsDungeon()
        {
            var csvServiceMoq     = new Mock <ICsvService>();
            var configurationMock = new Mock <IConfiguration>();

            var invalidDungeonsList = new Faker <DungeonMonster>()
                                      .RuleFor(n => n.Class, b => b.Random.String(10))
                                      .RuleFor(n => n.Constitution, b => b.Random.String())
                                      .RuleFor(n => n.Dexterity, b => b.Random.String())
                                      .RuleFor(n => n.DungeonNumber, b => b.Random.Int(min: 1))
                                      .RuleFor(n => n.Experience, b => b.Random.String())
                                      .RuleFor(n => n.HitPoints, b => b.Random.String())
                                      .RuleFor(n => n.Intelligence, b => b.Random.String())
                                      .RuleFor(n => n.Level, b => b.Random.Int())
                                      .RuleFor(n => n.Luck, b => b.Random.String())
                                      .RuleFor(n => n.MonsterLevel, b => b.Random.String())
                                      .RuleFor(n => n.MonsterName, b => b.Random.String())
                                      .RuleFor(n => n.Strength, b => b.Random.String())
                                      .Generate(10);

            var validDungeonsList = new Faker <DungeonMonster>()
                                    .RuleFor(n => n.Class, b => b.Random.String(10))
                                    .RuleFor(n => n.Constitution, b => b.Random.String())
                                    .RuleFor(n => n.Dexterity, b => b.Random.String())
                                    .RuleFor(n => n.DungeonNumber, () => - 1)
                                    .RuleFor(n => n.Experience, b => b.Random.String())
                                    .RuleFor(n => n.HitPoints, b => b.Random.String())
                                    .RuleFor(n => n.Intelligence, b => b.Random.String())
                                    .RuleFor(n => n.Level, b => b.Random.Int())
                                    .RuleFor(n => n.Luck, b => b.Random.String())
                                    .RuleFor(n => n.MonsterLevel, b => b.Random.String())
                                    .RuleFor(n => n.MonsterName, b => b.Random.String())
                                    .RuleFor(n => n.Strength, b => b.Random.String())
                                    .Generate(10);

            var dungeonList = new List <DungeonMonster>();

            dungeonList.AddRange(invalidDungeonsList);
            dungeonList.AddRange(validDungeonsList);


            configurationMock.Setup(n => n["CSVFilesLocation"]);
            csvServiceMoq.Setup(n => n.ReadRecordsFromCSVFile <DungeonMonster, DungeonMonsterMap>(It.IsAny <string>()))
            .Returns(dungeonList);

            var service = new DungeonService(configurationMock.Object, csvServiceMoq.Object);
            var result  = service.GetDungeonMonstersById(-1);

            result.Should().BeEquivalentTo(validDungeonsList);
        }
Beispiel #4
0
        public async Task RegisterCharacter_Should_Create_New_Dungeon_Character_Entity_In_Database()
        {
            using var context = await GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var dungeonService   = new DungeonService(context, characterService, mapper);

            await dungeonService.RegisterCharacterAsync("1", "1");

            var expected = 1;
            var actual   = context.DungeonCharacter.Count();

            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public async Task CreateAsync_Should_Throw_If_Incorrect_Destination_Provided()
        {
            using var context = await GetDatabase();

            var dungeonService = new DungeonService(context, null, null);

            var dungeonCreateBindingModel = new DungeonCreateBindingModel
            {
                DateTime    = DateTime.Now,
                Description = "TestDescr",
                Destination = "TestDest2",
                LeaderId    = "TestChar1"
            };

            await Assert.ThrowsAsync <ArgumentException>(async() => await dungeonService.CreateAsync(dungeonCreateBindingModel));
        }
Beispiel #6
0
        public async Task Edit_Should_Not_Update_If_Description_Is_Null_Or_Empty(string description)
        {
            using var context = await GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var dungeonService   = new DungeonService(context, characterService, mapper);

            var dungeonEditBindingModel = new DungeonEditBindingModel
            {
                DungeonId   = "1",
                Description = description
            };

            await dungeonService.EditAsync(dungeonEditBindingModel);

            var expected = "Initial";
            var actual   = context.Dungeons.First().Description;

            Assert.Equal(expected, actual);
        }
Beispiel #7
0
        public async Task Edit_Should_Properly_Edit_Character()
        {
            using var context = await GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var dungeonService   = new DungeonService(context, characterService, mapper);

            var dungeonEditBindingModel = new DungeonEditBindingModel
            {
                DungeonId   = "1",
                Description = "Updated"
            };

            await dungeonService.EditAsync(dungeonEditBindingModel);

            var expected = "Updated";
            var actual   = context.Dungeons.First().Description;

            Assert.Equal(expected, actual);
        }
Beispiel #8
0
        public async Task CreateAsync_Should_Register_Dungeon_In_Database()
        {
            using var context = await GetDatabase();

            var mapper           = this.GetMapper();
            var characterService = new CharacterService(context, mapper);
            var dungeonService   = new DungeonService(context, characterService, mapper);

            var dungeonCreateBindingModel = new DungeonCreateBindingModel
            {
                DateTime    = DateTime.Now,
                Description = "TestDescr",
                Destination = "TestDest",
                LeaderId    = "1"
            };

            await dungeonService.CreateAsync(dungeonCreateBindingModel);

            var expected = 2;
            var actual   = context.Dungeons.Count();

            Assert.Equal(expected, actual);
        }
        public void GetDungeons_ReturnsListOfDungeons()
        {
            var    configurationMock = new Mock <IConfiguration>();
            var    s      = Directory.GetCurrentDirectory();
            var    sArray = s.Split('\\');
            string dir    = "";

            foreach (var n in sArray)
            {
                dir += $"{n}\\";
                if (n == "sf-service")
                {
                    break;
                }
            }


            configurationMock.Setup(n => n["CSVFilesLocation"]).Returns(dir);
            var service = new DungeonService(configurationMock.Object, new CsvService());
            var results = service.GetAllDungeonMonsters();

            Assert.NotNull(results);
            Assert.True(results.Count > 0);
        }
Beispiel #10
0
 public SlabController(DungeonService dungeonService, SlabService slabService)
 {
     _dungeonService = dungeonService;
     _slabService    = slabService;
 }