public void GetWsForInputLanguage_GetsMatchingWsByCulture()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var kbdEn = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-US"
            };

            wsEn.LocalKeyboard = kbdEn;
            var kbdFr = new DefaultKeyboardDefinition()
            {
                Layout = "French", Locale = "fr-FR"
            };

            wsFr.LocalKeyboard = kbdFr;

            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsEn, new[] { wsEn, wsFr }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsFr, new[] { wsEn, wsFr }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsEn, new[] { wsFr, wsEn }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("en-US"), wsFr, new[] { wsFr, wsEn }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("fr-FR"), wsEn, new[] { wsFr, wsEn }), Is.EqualTo(wsFr));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("fr-FR"), wsEn, new[] { wsEn, wsFr }), Is.EqualTo(wsFr));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("", new CultureInfo("fr-FR"), null, new[] { wsEn, wsFr }), Is.EqualTo(wsFr));
        }
        public void GetWsForInputLanguage_PrefersCurrentLayoutIfTwoMatch()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var kbdEn = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-US"
            };

            wsEn.LocalKeyboard = kbdEn;
            var kbdFr = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "fr-US"
            };

            wsFr.LocalKeyboard = kbdFr;

            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsEn, new[] { wsEn, wsFr }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsFr, new[] { wsEn, wsFr }), Is.EqualTo(wsFr));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsEn, new[] { wsFr, wsEn }), Is.EqualTo(wsEn));
            Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsFr, new[] { wsFr, wsEn }), Is.EqualTo(wsFr));
        }
        public void SettingLocalKeyboardSettings_CausesLocalKeyboardToBeSetOnWritingSystemCreatedLater()
        {
            RepositoryUnderTest.LocalKeyboardSettings =
                @"<keyboards>
	<keyboard ws='en' layout='English' locale='en-AU'/>
	<keyboard ws='fr' layout='French-IPA' locale='fr-FR'/>
	<keyboard ws='de' layout='German-IPA' locale='de-DE'/>
</keyboards>";
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var wsDe = new WritingSystemDefinition("de");

            wsDe.LocalKeyboard = new DefaultKeyboardDefinition()
            {
                Layout = "German", Locale = "de-SW"
            };
            RepositoryUnderTest.Set(wsDe);

            Assert.That(wsEn.LocalKeyboard.Locale, Is.EqualTo("en-AU"));
            Assert.That(wsFr.LocalKeyboard.Layout, Is.EqualTo("French-IPA"));
            Assert.That(wsEn.LocalKeyboard.OperatingSystem, Is.EqualTo(Environment.OSVersion.Platform));
            Assert.That(wsDe.LocalKeyboard.Layout, Is.EqualTo("German"), "should not apply local keyboard settings if new WS already has them");
        }
            public async void Should_merge_the_entities()
            {
                // Arrange
                const string partitionKey               = "MergeAsync";
                const string rowKey                     = "MyKey";
                const string expectedSomePropValue      = "SomeFinalValue";
                const string expectedSomeOtherPropValue = "SomeOtherValue";
                await SomeOtherTestEntityRepository.InsertOrReplaceAsync(new SomeOtherTestEntity
                {
                    PartitionKey  = partitionKey,
                    RowKey        = rowKey,
                    ETag          = "*",
                    SomeOtherProp = expectedSomeOtherPropValue
                });

                // Act
                var result = await RepositoryUnderTest.MergeAsync(new SomeTestEntity
                {
                    PartitionKey = partitionKey,
                    RowKey       = rowKey,
                    ETag         = "*",
                    SomeProp     = expectedSomePropValue
                });

                // Assert
                var entity1 = await RepositoryUnderTest.ReadOneAsync(partitionKey, rowKey);

                var entity2 = await SomeOtherTestEntityRepository.ReadOneAsync(partitionKey, rowKey);

                Assert.NotNull(entity1);
                Assert.NotNull(entity2);
                Assert.Equal(expectedSomePropValue, entity1.SomeProp);
                Assert.Equal(expectedSomeOtherPropValue, entity2.SomeOtherProp);
            }
Esempio n. 5
0
            public async Task Should_map_ReadOne_and_return_the_expected_ninja()
            {
                // Arrange
                var clanName      = "My clan";
                var ninjaKey      = "123FB950-57DB-4CD0-B4D1-7E6B00A6163A";
                var entity        = new NinjaEntity();
                var expectedNinja = new Ninja();

                NinjaEntityTableStorageRepositoryMock
                .Setup(x => x.ReadOneAsync(clanName, ninjaKey))
                .ReturnsAsync(entity)
                .Verifiable();
                NinjaMappingServiceMock
                .Setup(x => x.Map(entity))
                .Returns(expectedNinja)
                .Verifiable();

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(clanName, ninjaKey);

                // Assert
                NinjaMappingServiceMock
                .Verify(x => x.Map(entity), Times.Once);
                NinjaEntityTableStorageRepositoryMock
                .Verify(x => x.ReadOneAsync(clanName, ninjaKey), Times.Once);
                Assert.Same(expectedNinja, result);
            }
            public async void Should()
            {
                // Arrange
                await RepositoryUnderTest.InsertOrReplaceAsync(new SomeTestEntity
                {
                    PartitionKey = "Partition1",
                    RowKey       = "Key1"
                });

                await RepositoryUnderTest.InsertOrReplaceAsync(new SomeTestEntity
                {
                    PartitionKey = "Partition1",
                    RowKey       = "Key2"
                });

                await RepositoryUnderTest.InsertOrReplaceAsync(new SomeTestEntity
                {
                    PartitionKey = "Partition2",
                    RowKey       = "Key1"
                });

                // Act
                var result = await RepositoryUnderTest.ReadAllAsync();

                // Assert
                Assert.NotNull(result);
                Assert.Equal(3, result.Count());
            }
            public async void Should_replace_an_entity()
            {
                // Arrange
                const string partitionKey  = "ReplaceAsync";
                const string rowKey        = "MyKey";
                const string expectedValue = "SomeOtherValue";
                await RepositoryUnderTest.InsertOrReplaceAsync(new SomeTestEntity
                {
                    PartitionKey = partitionKey,
                    RowKey       = rowKey,
                    ETag         = "*",
                    SomeProp     = "SomeValue"
                });

                // Act
                var result = await RepositoryUnderTest.ReplaceAsync(new SomeTestEntity
                {
                    PartitionKey = partitionKey,
                    RowKey       = rowKey,
                    ETag         = "*",
                    SomeProp     = expectedValue
                });

                // Assert
                Assert.NotNull(result);
                var entity = await RepositoryUnderTest.ReadOneAsync(partitionKey, rowKey);

                Assert.Equal(expectedValue, entity.SomeProp);
            }
            public async void Should_delete_a_partition()
            {
                // Arrange
                const string partitionName = "DeletePartitionAsync";
                var          entity1       = new SomeTestEntity
                {
                    PartitionKey = partitionName,
                    RowKey       = "MyKey1"
                };
                var entity2 = new SomeTestEntity
                {
                    PartitionKey = partitionName,
                    RowKey       = "MyKey2"
                };
                await RepositoryUnderTest.InsertOrReplaceAsync(entity1);

                await RepositoryUnderTest.InsertOrReplaceAsync(entity2);

                // Act
                var result = await RepositoryUnderTest.DeletePartitionAsync(partitionName);

                // Assert
                Assert.NotNull(result);
                Assert.Equal(2, result.Count());
                var dbResult = await RepositoryUnderTest.ReadPartitionAsync(partitionName);

                Assert.NotNull(dbResult);
                Assert.Equal(0, dbResult.Count());
            }
            public async void Should_insert_an_entity()
            {
                // Arrange
                const string partitionName = "InsertAsync";
                const string rowKey        = "MyKey";
                const string expectedValue = "SomeValue";
                var          entity        = new SomeTestEntity
                {
                    PartitionKey = partitionName,
                    RowKey       = rowKey,
                    SomeProp     = expectedValue
                };

                var persistedEntity = await RepositoryUnderTest.ReadOneAsync(partitionName, rowKey);

                if (persistedEntity != null)
                {
                    await RepositoryUnderTest.DeleteOneAsync(partitionName, rowKey);
                }

                // Act
                var result = await RepositoryUnderTest.InsertAsync(entity);

                // Assert
                Assert.NotNull(result);
                var dbResult = await RepositoryUnderTest.ReadOneAsync(partitionName, rowKey);

                Assert.NotNull(dbResult);
                Assert.Equal(expectedValue, dbResult.SomeProp);
            }
            public async Task ReadAllAsync_Returns_Workouts()
            {
                // Arrange
                var expectedWorkouts = new[]
                {
                    new Workout {
                        Name = "Test workout 01"
                    },
                    new Workout {
                        Name = "Test workout 02"
                    },
                    new Workout {
                        Name = "Test workout 03"
                    }
                };

                TrainingPlanContextMock.Workouts.AddRange(expectedWorkouts);
                await TrainingPlanContextMock.SaveChangesAsync();

                // Act
                var result = await RepositoryUnderTest.ReadAllAsync();

                // Assert
                Assert.Collection(result,
                                  workout => Assert.Same(expectedWorkouts[0], workout),
                                  workout => Assert.Same(expectedWorkouts[1], workout),
                                  workout => Assert.Same(expectedWorkouts[2], workout)
                                  );
            }
Esempio n. 11
0
            public async Task Should_map_InsertOrMerge_and_return_the_expected_ninja()
            {
                // Arrange
                var ninjaToUpdate  = new Ninja();
                var entityToUpdate = new NinjaEntity();
                var updatedEntity  = new NinjaEntity();
                var expectedNinja  = new Ninja();

                NinjaMappingServiceMock
                .Setup(x => x.Map(ninjaToUpdate))
                .Returns(entityToUpdate)
                .Verifiable();
                NinjaEntityTableStorageRepositoryMock
                .Setup(x => x.InsertOrMergeAsync(entityToUpdate))
                .ReturnsAsync(updatedEntity)
                .Verifiable();
                NinjaMappingServiceMock
                .Setup(x => x.Map(updatedEntity))
                .Returns(expectedNinja)
                .Verifiable();

                // Act
                var result = await RepositoryUnderTest.UpdateAsync(ninjaToUpdate);

                // Assert
                NinjaMappingServiceMock.Verify(x => x.Map(ninjaToUpdate), Times.Once);
                NinjaEntityTableStorageRepositoryMock.Verify(x => x.InsertOrMergeAsync(entityToUpdate), Times.Once);
                NinjaMappingServiceMock.Verify(x => x.Map(updatedEntity), Times.Once);
                Assert.Same(expectedNinja, result);
            }
Esempio n. 12
0
            public async Task Should_map_ReadPartition_and_return_the_expected_ninja()
            {
                // Arrange
                var clanName      = "My clan";
                var entities      = new NinjaEntity[0];
                var expectedNinja = new Ninja[0];

                NinjaEntityTableStorageRepositoryMock
                .Setup(x => x.ReadPartitionAsync(clanName))
                .ReturnsAsync(entities)
                .Verifiable();
                NinjaMappingServiceMock
                .Setup(x => x.Map(entities))
                .Returns(expectedNinja)
                .Verifiable();

                // Act
                var result = await RepositoryUnderTest.ReadAllInClanAsync(clanName);

                // Assert
                NinjaMappingServiceMock
                .Verify(x => x.Map(entities), Times.Once);
                NinjaEntityTableStorageRepositoryMock
                .Verify(x => x.ReadPartitionAsync(clanName), Times.Once);
                Assert.Same(expectedNinja, result);
            }
        public void LocalKeyboardSettings_RetrievesLocalKeyboardData()
        {
            var wsEn = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(wsEn);
            var wsFr = new WritingSystemDefinition("fr");

            RepositoryUnderTest.Set(wsFr);
            var kbd1 = new DefaultKeyboardDefinition()
            {
                Layout = "English", Locale = "en-GB", OperatingSystem = PlatformID.Win32NT
            };

            wsEn.LocalKeyboard = kbd1;

            var result = RepositoryUnderTest.LocalKeyboardSettings;
            var root   = XElement.Parse(result);

            Assert.That(root.Elements("keyboard").Count(), Is.EqualTo(1), "should have local keyboard for en but not fr");
            var keyboardElt = root.Elements("keyboard").First();

            Assert.That(keyboardElt.Attribute("layout").Value, Is.EqualTo("English"));
            Assert.That(keyboardElt.Attribute("locale").Value, Is.EqualTo("en-GB"));
            Assert.That(keyboardElt.Attribute("ws").Value, Is.EqualTo("en"));
        }
Esempio n. 14
0
        public void WritingSystemIdHasChangedTo_IdExistsAndHasNeverChanged_ReturnsId()
        {
            //Add a writing system to the repo
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Save();
            Assert.That(RepositoryUnderTest.WritingSystemIdHasChangedTo("en"), Is.EqualTo("en"));
        }
Esempio n. 15
0
        public void Remove_WritingsystemIdExists_FiresEventAndEventArgIsSetToIdOfDeletedWritingSystem()
        {
            RepositoryUnderTest.WritingSystemDeleted += OnWritingsystemDeleted;
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Remove(ws.LanguageTag);
            Assert.That(_writingSystemDeletedEventArgs.Id, Is.EqualTo(ws.LanguageTag));
        }
Esempio n. 16
0
            public async Task Deve_retornar_o_usuario_esperado()
            {
                // Arrange

                // Act
                var result = await RepositoryUnderTest.GetByIdAsync(testId);

                // Assert
                Assert.Equal("*****@*****.**", result.Email);
            }
Esempio n. 17
0
            public async Task Deve_retornar_todos_os_usuario()
            {
                // Arrange

                // Act
                var result = await RepositoryUnderTest.GetAllAsync();

                // Assert
                Assert.Equal(3, result.Count());
            }
Esempio n. 18
0
            public async Task Deve_retornar_vazio()
            {
                // Arrange
                var id = Guid.NewGuid();

                // Act
                var result = await RepositoryUnderTest.GetByIdAsync(id);

                // Assert
                Assert.Null(result);
            }
Esempio n. 19
0
            public async Task Should_return_null_if_the_clan_does_not_exist()
            {
                // Arrange
                var unexistingClanName = "Unexisting clan";

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(unexistingClanName);

                // Assert
                Assert.Null(result);
            }
            public async Task ReadOneAsync_Returns_Null_When_WorkoutDoesNotExist()
            {
                // Arrange
                const int id = 1;

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(id);

                // Assert
                Assert.Null(result);
            }
            public void Delete_Returns_Null_When_WorkoutDoesNotExist()
            {
                // Arrange
                const int id = 1;

                // Act
                var result = RepositoryUnderTest.Delete(id);

                // Assert
                Assert.Null(result);
            }
Esempio n. 22
0
            public async Task ShouldReturnNullIfTheClanDoesNotExist()
            {
                //Arrange
                string clanName = "Not Exist Clan";

                //Act
                var result = await RepositoryUnderTest.ReadOneAsync(clanName);

                //Assert
                Assert.Null(result);
            }
Esempio n. 23
0
            public async Task Should_return_the_expected_clan()
            {
                // Arrange
                var expectedClan     = Clans[1];
                var expectedClanName = expectedClan.Name;

                // Act
                var result = await RepositoryUnderTest.ReadOneAsync(expectedClanName);

                // Assert
                Assert.Same(expectedClan, result);
            }
Esempio n. 24
0
            public async Task Should_return_all_clans()
            {
                // Act
                var result = await RepositoryUnderTest.ReadAllAsync();

                // Assert
                Assert.Collection(result,
                                  clan => Assert.Same(Clans[0], clan),
                                  clan => Assert.Same(Clans[1], clan),
                                  clan => Assert.Same(Clans[2], clan)
                                  );
            }
Esempio n. 25
0
        public void WritingSystemIdHasChangedTo_IdChanged_ReturnsNewId()
        {
            //Add a writing system to the repo
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Save();
            //Now change the Id
            ws.Variants.Add("bogus");
            RepositoryUnderTest.Save();
            Assert.That(RepositoryUnderTest.WritingSystemIdHasChangedTo("en"), Is.EqualTo("en-x-bogus"));
        }
        public void WritingSystemIdHasBeenChanged_IdChanged_ReturnsTrue()
        {
            //Add a writing system to the repo
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Save();
            //Now change the Id
            ws.Variant = "x-bogus";
            RepositoryUnderTest.Save();
            Assert.That(RepositoryUnderTest.WritingSystemIdHasChanged("en"), Is.True);
        }
            public async Task UpdateAsync_Returns_Null_When_Workout_DoesNotExist()
            {
                // Arrange
                var expectedWorkout = new Workout {
                    Name = "Test workout 01"
                };

                // Act
                var result = await RepositoryUnderTest.UpdateAsync(expectedWorkout);

                // Assert
                Assert.Null(result);
            }
            public async Task CreateAsync_Creates_And_Returns_Workout()
            {
                // Arrange
                var expectedWorkout = new Workout {
                    Name = "Test workout 01"
                };

                // Act
                var result = await RepositoryUnderTest.CreateAsync(expectedWorkout);

                // Assert
                Assert.Same(expectedWorkout, result);
            }
            public void Update_Returns_Null_When_WorkoutDoesNotExist()
            {
                // Arrange
                var expectedWorkout = new Workout {
                    Name = "Test workout 01"
                };

                // Act
                var result = RepositoryUnderTest.Update(expectedWorkout);

                // Assert
                Assert.Null(result);
            }
            public void Create_Creates_And_Returns_Workout()
            {
                // Arrange
                var expectedWorkout = new Workout {
                    Name = "Test workout 01"
                };

                // Act
                var result = RepositoryUnderTest.Create(expectedWorkout);

                // Assert
                Assert.Same(expectedWorkout, result);
            }