Example #1
0
		public async Task ObserveValue_ValueDoesNotExists_ShouldSaveDefaultValue(
			[Frozen]Mock<IAsyncStorage> table,
			Services.SettingsService sut,
			string key,
			object expected)
		{
			//arrange
			table.Setup(t => t.Contains<string, object>(key, It.IsAny<CancellationToken>())).ReturnsTask(false);
			var verifiable = table.Setup(t => t.AddOrUpdate(key, expected, It.IsAny<CancellationToken>())).ReturnsDefaultTaskVerifiable();

			//act
			await sut.ObserveValue<object>(key, () => expected).Take(1);

			//assert
			verifiable.Verify();
		}
Example #2
0
		public async Task ObserveValue_ValueExists_ShouldReturnCorrectValue(
			[Frozen]Mock<IAsyncStorage> table,
			Services.SettingsService sut,
			string key,
			object expected)
		{
			//arrange
			table.Setup(t => t.Get<string, object>(key, It.IsAny<CancellationToken>())).ReturnsTask(expected);
			table.Setup(t => t.Contains<string, object>(key, It.IsAny<CancellationToken>())).ReturnsTask(true);

			//act
			var actual = await sut.ObserveValue<object>(key, () => null).Take(1);

			//assert
			actual.Should().Be(expected);
		}
Example #3
0
		public async Task ObserveValue_ValueDoesNotExists_ShouldReturnDefaultValue(
			[Frozen]Mock<IAsyncStorage> table,
			Services.SettingsService sut,
			string key,
			object expected)
		{
			//arrange
			table.Setup(t => t.Get<string, object>(key, It.IsAny<CancellationToken>())).ReturnsTask(() => null);
			table.Setup(t => t.Contains<string, object>(key, It.IsAny<CancellationToken>())).ReturnsTask(false);
			table.Setup(t => t.AddOrUpdate(key, expected, It.IsAny<CancellationToken>())).ReturnsDefaultTask();

			//act
			var actual = await sut.ObserveValue<object>(key, () => expected).Take(1);

			//assert
			actual.Should().Be(expected);
		}
Example #4
0
		public async Task ObserveValue_WhenCallSet_ShouldReturnValue(
			[Frozen]ThrowingTestScheduler scheduler,
			[Frozen]Mock<IAsyncStorage> table,
			Services.SettingsService sut,
			string key,
			object expected)
		{
			//arrange
			table.Setup(t => t.Contains<string, object>(key, It.IsAny<CancellationToken>())).ReturnsTask(false);
			table.Setup(t => t.AddOrUpdate(key, It.IsAny<object>(), It.IsAny<CancellationToken>())).ReturnsDefaultTask();
			
			//act
			var observer = scheduler.CreateObserver<object>();
			sut.ObserveValue(key, () => default(object)).Skip(1).Subscribe(observer);
			await sut.SetValue(key, expected, CancellationToken.None);
			
			//assert
			observer.Values().Last().Should().Be(expected);
		}