Exemplo n.º 1
0
        public void GetPlayerPartByPartId_ShoudlReturnCorrectPlayerParts()
        {
            var options = GetDbOptions("GetPlayerPartByPartId_Database");

            var dummyPlayer = new Player()
            {
                UserName = "******"
            };

            var dummyPart1 = new Part()
            {
                Id = 1
            };
            var dummyPart2 = new Part()
            {
                Id = 2
            };

            var dummyPlayerPart1 = new PlayerParts()
            {
                Id = 12, Player = dummyPlayer, Part = dummyPart1
            };
            var dummyPlayerPart2 = new PlayerParts()
            {
                Id = 21, Player = dummyPlayer, Part = dummyPart2
            };

            using (var context = new RiderDBContext(options))
            {
                context.PlayerParts.Add(dummyPlayerPart1);
                context.PlayerParts.Add(dummyPlayerPart2);
                context.SaveChanges();
            }

            PlayerParts actual;

            using (var context = new RiderDBContext(options))
            {
                var partsService = new PartsService(context);
                actual = partsService.GetPlayerPartByPartId("Dummy", 2);
            }

            Assert.Equal(21, actual.Id);

            using (var context = new RiderDBContext(options))
            {
                var partsService = new PartsService(context);
                actual = partsService.GetPlayerPartByPartId("Dummy", 1);
            }

            Assert.Equal(12, actual.Id);

            using (var context = new RiderDBContext(options))
            {
                var partsService = new PartsService(context);
                actual = partsService.GetPlayerPartByPartId("Dummy", 3);
            }

            Assert.Null(actual);
        }