public void DisusePart_ShouldSetIsUsedFalseAndRemoveBikePartId() { var options = GetDbOptions("DisusePart_Database"); var dummyBikePart = new BikeParts(); var dummyPlayerPart1 = new PlayerParts() { Id = 10, IsUsed = true, BikePart = dummyBikePart }; var dummyPlayerPart2 = new PlayerParts() { Id = 20, IsUsed = true, BikePart = dummyBikePart }; var dummyPlayerPart3 = new PlayerParts() { Id = 30, IsUsed = true, BikePart = dummyBikePart }; using (var context = new RiderDBContext(options)) { context.PlayerParts.Add(dummyPlayerPart1); context.PlayerParts.Add(dummyPlayerPart2); context.PlayerParts.Add(dummyPlayerPart3); context.SaveChanges(); } Assert.True(dummyPlayerPart1.IsUsed); Assert.True(dummyPlayerPart2.IsUsed); Assert.NotNull(dummyPlayerPart1.BikePart); Assert.NotNull(dummyPlayerPart2.BikePart); PlayerParts actual1; PlayerParts actual2; bool isDisused1; bool isDisused2; bool isDisused3; using (var context = new RiderDBContext(options)) { var userManager = GetMockUserManager(); var playersService = new PlayersService(context, userManager.Object); isDisused1 = playersService.DisusePart(10); isDisused2 = playersService.DisusePart(20); isDisused3 = playersService.DisusePart(221); actual1 = context.PlayerParts.FirstOrDefault(x => x.Id == 10); actual2 = context.PlayerParts.FirstOrDefault(x => x.Id == 20); } Assert.True(isDisused1); Assert.True(isDisused2); Assert.False(isDisused3); Assert.False(actual1.IsUsed); Assert.False(actual2.IsUsed); Assert.Null(actual1.BikePart); Assert.Null(actual2.BikePart); }