|
6 | 6 | using Refresh.Database.Models.Levels; |
7 | 7 | using Refresh.Database.Models.Photos; |
8 | 8 | using Refresh.Interfaces.Game.Types.Lists; |
| 9 | +using Refresh.Database.Helpers; |
9 | 10 |
|
10 | 11 | namespace RefreshTests.GameServer.Tests.Photos; |
11 | 12 |
|
@@ -83,6 +84,89 @@ public void UploadAndDeletePhoto() |
83 | 84 | response = message.Content.ReadAsXML<SerializedPhotoList>(); |
84 | 85 | Assert.That(response.Items, Has.Count.EqualTo(0)); |
85 | 86 | } |
| 87 | + |
| 88 | + [Test] |
| 89 | + public void UploadPhotoAndValidateAttributes() |
| 90 | + { |
| 91 | + using TestContext context = this.GetServer(); |
| 92 | + GameUser user = context.CreateUser(); |
| 93 | + GameLevel level = context.Database.GetStoryLevelById(420); |
| 94 | + |
| 95 | + using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user); |
| 96 | + |
| 97 | + //Upload our """photo""" |
| 98 | + HttpResponseMessage message = client.PostAsync($"/lbp/upload/{TEST_ASSET_HASH}", new ReadOnlyMemoryContent(TestAsset)).Result; |
| 99 | + Assert.That(message.StatusCode, Is.EqualTo(OK)); |
| 100 | + DateTimeOffset takenAt = context.Time.Now; |
| 101 | + context.Time.TimestampMilliseconds += 2000; // Increase to differentiate between creation and publish date |
| 102 | + |
| 103 | + SerializedPhoto photo = new() |
| 104 | + { |
| 105 | + Timestamp = takenAt.ToUnixTimeSeconds(), |
| 106 | + AuthorName = user.Username, |
| 107 | + SmallHash = TEST_ASSET_HASH, |
| 108 | + MediumHash = TEST_ASSET_HASH, |
| 109 | + LargeHash = TEST_ASSET_HASH, |
| 110 | + PlanHash = TEST_ASSET_HASH, |
| 111 | + Level = new SerializedPhotoLevel |
| 112 | + { |
| 113 | + LevelId = level.StoryId, |
| 114 | + Title = "real title", |
| 115 | + Type = "developer", |
| 116 | + }, |
| 117 | + PhotoSubjects = new List<SerializedPhotoSubject> |
| 118 | + { |
| 119 | + new() |
| 120 | + { |
| 121 | + Username = user.Username, |
| 122 | + DisplayName = user.Username, |
| 123 | + BoundsList = "1,1,1,1", |
| 124 | + }, |
| 125 | + new() |
| 126 | + { |
| 127 | + Username = "SecretAlt", |
| 128 | + DisplayName = "SecretAlt", |
| 129 | + BoundsList = "2,4,5,6", |
| 130 | + }, |
| 131 | + } |
| 132 | + }; |
| 133 | + message = client.PostAsync($"/lbp/uploadPhoto", new StringContent(photo.AsXML())).Result; |
| 134 | + Assert.That(message.StatusCode, Is.EqualTo(OK)); |
| 135 | + |
| 136 | + // Get the photo |
| 137 | + GamePhoto? gamePhoto = context.Database.GetPhotosByUser(user, 100, 0).Items.FirstOrDefault(); |
| 138 | + Assert.That(gamePhoto, Is.Not.Null); |
| 139 | + |
| 140 | + Assert.That(gamePhoto!.PublisherId, Is.EqualTo(user.UserId)); |
| 141 | + Assert.That(gamePhoto!.Publisher.UserId, Is.EqualTo(user.UserId)); |
| 142 | + Assert.That(gamePhoto!.PublisherId, Is.EqualTo(user.UserId)); |
| 143 | + |
| 144 | + Assert.That(gamePhoto!.TakenAt, Is.EqualTo(takenAt)); |
| 145 | + Assert.That(gamePhoto!.PublishedAt, Is.EqualTo(context.Time.Now)); |
| 146 | + Assert.That(gamePhoto!.PublishedAt, Is.Not.EqualTo(gamePhoto.TakenAt)); // Should be apart by 2 seconds (see above) |
| 147 | + |
| 148 | + Assert.That(gamePhoto!.Level!, Is.Not.Null); |
| 149 | + Assert.That(gamePhoto!.Level!.LevelId, Is.EqualTo(level.LevelId)); |
| 150 | + Assert.That(gamePhoto!.LevelId, Is.EqualTo(level.LevelId)); |
| 151 | + Assert.That(gamePhoto!.OriginalLevelId, Is.EqualTo(level.StoryId)); |
| 152 | + Assert.That(gamePhoto!.LevelType, Is.EqualTo("developer")); |
| 153 | + Assert.That(gamePhoto!.OriginalLevelName, Is.EqualTo("real title")); |
| 154 | + |
| 155 | + Assert.That(gamePhoto!.SmallAssetHash, Is.EqualTo(TEST_ASSET_HASH)); |
| 156 | + Assert.That(gamePhoto!.MediumAssetHash, Is.EqualTo(TEST_ASSET_HASH)); |
| 157 | + Assert.That(gamePhoto!.LargeAssetHash, Is.EqualTo(TEST_ASSET_HASH)); |
| 158 | + Assert.That(gamePhoto!.PlanHash, Is.EqualTo(TEST_ASSET_HASH)); |
| 159 | + |
| 160 | + Assert.That(gamePhoto!.Subjects.Count, Is.EqualTo(2)); |
| 161 | + Assert.That(gamePhoto!.Subjects[0].Bounds, Is.EqualTo(PhotoHelper.ParseBoundsList("1,1,1,1"))); |
| 162 | + Assert.That(gamePhoto!.Subjects[0].DisplayName, Is.EqualTo(user.Username)); |
| 163 | + Assert.That(gamePhoto!.Subjects[0].User, Is.Not.Null); |
| 164 | + Assert.That(gamePhoto!.Subjects[0].User!.UserId, Is.EqualTo(user.UserId)); |
| 165 | + |
| 166 | + Assert.That(gamePhoto!.Subjects[1].Bounds, Is.EqualTo(PhotoHelper.ParseBoundsList("2,4,5,6"))); |
| 167 | + Assert.That(gamePhoto!.Subjects[1].DisplayName, Is.EqualTo("SecretAlt")); |
| 168 | + Assert.That(gamePhoto!.Subjects[1].User, Is.Null); |
| 169 | + } |
86 | 170 |
|
87 | 171 | [Test] |
88 | 172 | public void CantUploadPhotoWithMissingAssets() |
|
0 commit comments