@@ -52,7 +52,7 @@ public GameLevel AddLevel(ISerializedPublishLevel createInfo, TokenGame game, Ga
5252 EnforceMinMaxPlayers = createInfo . EnforceMinMaxPlayers ,
5353 SameScreenGame = createInfo . SameScreenGame ,
5454 BackgroundGuid = createInfo . BackgroundGuid ,
55- PublisherUserId = publisher . UserId ,
55+ Publisher = publisher ,
5656 GameVersion = game ,
5757 PublishDate = timestamp ,
5858 UpdateDate = timestamp ,
@@ -61,31 +61,24 @@ public GameLevel AddLevel(ISerializedPublishLevel createInfo, TokenGame game, Ga
6161 this . ApplyLevelMetadataFromAttributes ( level ) ;
6262 this . GameLevels . Add ( level ) ;
6363
64- this . SaveChanges ( ) ;
65-
66- this . CreateRevisionForLevel ( level , level . Publisher ) ;
67- this . GameLevelStatistics . Add ( level . Statistics = new GameLevelStatistics
68- {
69- LevelId = level . LevelId ,
70- } ) ;
64+ // Seems unnecessary, but prevents EF from trying to INSERT both unconditionally in unit tests
65+ this . GameUsers . Update ( publisher ) ;
66+ if ( publisher . Statistics != null )
67+ this . GameUserStatistics . Update ( publisher . Statistics ) ;
7168
7269 this . SaveChanges ( ) ;
7370
74- if ( publisher != null )
71+ this . WriteEnsuringStatistics ( publisher , ( ) =>
7572 {
76- this . WriteEnsuringStatistics ( publisher , ( ) =>
73+ this . GameLevelStatistics . Add ( level . Statistics = new GameLevelStatistics
7774 {
78- // even if the level count does get updated, ChangeTracker.HasChanges() will return false anyways
79- // (in unit tests atleast), failing the assert
80- this . GameUsers . Update ( publisher ) ;
81- publisher . Statistics ! . LevelCount ++ ;
75+ LevelId = level . LevelId ,
8276 } ) ;
83- }
8477
85- // setting Publisher on an untracked object prevents EF from unconditionally trying to INSERT the publisher into the
86- // GameUsers table on the next SaveChanges() call in unit tests, causing a duplicate key exception
87- level = level . Clone ( ) ;
88- level . Publisher = publisher ;
78+ this . CreateRevisionForLevel ( level , level . Publisher ) ;
79+ publisher . Statistics ! . LevelCount ++ ;
80+ } ) ;
81+
8982 return level ;
9083 }
9184
0 commit comments