public void Assertions() { var condition = false; var text = "something"; var obj = new Auto(); var tokens = new List <string> { "public", "void", "return" }; var zero = 8 - 8; var someEnumerable = new List <string>(); Assert.False(condition); Assert.Equal("something", text); Assert.NotEqual("something else", text); Assert.Contains("tech", "technology"); // also DoesNotContain Assert.Matches(".*thing$", "something"); Assert.Throws <DivideByZeroException>(() => 4 / zero); Assert.Empty(someEnumerable); // also NotEmpty Assert.IsType <Auto>(obj); Assert.Collection(new List <int> { 2, 4 }, n => Assert.Equal(2, n), n => Assert.Equal(4, n) ); Assert.All(new List <string> { "a", "ab", "abc" }, s => s.StartsWith("a")); }
public async Task Given_Update_Data_Update_Already_Existing_Email() { var tokenEnvironmentVariable = Environment.GetEnvironmentVariable("Token"); var environmentVariable = Environment.GetEnvironmentVariable("User"); var jObject = JObject.Parse(environmentVariable); var userDto = jObject.ToObject <UserDto>(); userDto.Email = "*****@*****.**"; var serialize = JsonConvert.SerializeObject(userDto); var content = new StringContent(serialize, Encoding.UTF8, "application/json"); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenEnvironmentVariable); var defaultPage = await _client.PutAsync("/api/users/" + userDto.Id, content); var readAsStringAsync = defaultPage.Content.ReadAsStringAsync(); var defaultPager = await _client.GetAsync("/api/users/" + userDto.Id); var asStringAsync = defaultPager.Content.ReadAsStringAsync(); var result = asStringAsync.Result; var resultObject = JObject.Parse(result); var dto = resultObject.ToObject <UserDto>(); Assert.Equal(HttpStatusCode.OK, defaultPager.StatusCode); Assert.NotNull(environmentVariable); Assert.IsType <UserDto>(dto); Assert.NotEqual(dto.Email, userDto.Email); Assert.Equal(HttpStatusCode.BadRequest, defaultPage.StatusCode); Assert.InRange(readAsStringAsync.Result.Length, 10, int.MaxValue); }
public async Task Edit() { var config = await this.Add(); var template = await this._templateController.Add(); var message = new HttpRequestMessage(HttpMethod.Put, API); var commond = new ConfigChangeCommand { Id = config.Id, Name = template.Name, Content = template.Format, TemplateId = template.Id }; message.AddJsonContent(commond); var responseMessage = await this.HttpClient.SendAsync(message); await responseMessage.AsResult(); var newConfig = await this.Get(config.Id); Assert.NotEqual(commond.Name, config.Name); Assert.NotEqual(commond.Content, config.Content); Assert.NotEqual(commond.TemplateId, config.TemplateId); Assert.Equal(commond.Name, newConfig.Name); Assert.Equal(commond.TemplateId, newConfig.TemplateId); Assert.Equal(commond.Content, newConfig.Content); }
public void Inequality() { int expectedValue = 3; int actualValue = 3; // MSTest MSTestAssert.AreNotEqual(expectedValue, actualValue, "Some context"); // Assert.AreNotEqual failed. Expected any value except:<3>. Actual:<3>. Some context // NUnit Assert.That(actualValue, Is.Not.EqualTo(expectedValue), () => "Some context"); // Some context // Expected: not equal to 3 // But was: 3 // XUnit XUnitAssert.NotEqual(expectedValue, actualValue); // Assert.NotEqual() Failure // Expected: Not 3 // Actual: 3 // Fluent actualValue.Should().NotBe(expectedValue, "SOME REASONS"); // Did not expect actualValue to be 3 because SOME REASONS. // Shouldly actualValue.ShouldNotBe(expectedValue, "Some context"); // actualValue // should not be // 3 // but was // // Additional Info: // Some context }
public void ApproximateInequalityOfFloatingPointNumbers() { double pi = 3.14; // MSTest MSTestAssert.AreNotEqual(Math.PI, pi, 0.01, "Some context"); // Assert.AreNotEqual failed. Expected a difference greater than <0.01> between expected value <3.14159265358979> and actual value <3.14>. Some context // NUnit Assert.That(pi, Is.Not.EqualTo(Math.PI).Within(0.1).Percent, () => "Some context"); // Some context // Expected: not equal to 3.1415926535897931d +/- 0.10000000000000001d Percent // But was: 3.1400000000000001d // XUnit XUnitAssert.NotEqual(Math.PI, pi, 1); // Message: Assert.NotEqual() Failure // Expected: Not 3.1 (rounded from 3.14159265358979) // Actual: 3.1 (rounded from 3.14) // Fluent pi.Should().NotBeApproximately(Math.PI, 0.01, "SOME REASONS"); // Expected pi to not approximate 3.1415926535897931 +/- 0.01 because SOME REASONS, but 3.14 only differed by 0.001592653589793223. // Shouldly does not support this case. }
public async Task GetByIdsAsync_GetThenSaveNotification_ReturnCachedNotification() { //Arrange var id = Guid.NewGuid().ToString(); var newNotification = new ConfirmationEmailNotification { Id = id }; var newNotificationEntity = AbstractTypeFactory <NotificationEntity> .TryCreateInstance(nameof(EmailNotificationEntity)).FromModel(newNotification, new PrimaryKeyResolvingMap()); var service = GetNotificationServiceWithPlatformMemoryCache(); _repositoryMock.Setup(x => x.Add(newNotificationEntity.ResetEntityData())) .Callback(() => { _repositoryMock.Setup(o => o.GetByIdsAsync(new[] { id }, null)) .ReturnsAsync(new[] { newNotificationEntity }); }); //Act var emptyNotifications = await service.GetByIdsAsync(new[] { id }, null); await service.SaveChangesAsync(new[] { newNotification }); var notifications = await service.GetByIdsAsync(new[] { id }, null); //Assert Assert.NotEqual(emptyNotifications, notifications); }
public void IdentifyLongCodeTokenTypes() { TextReader testProgramStream = File.OpenText(@"CorrectSampleLuaFiles\longcode.lua"); List <Token> tokenList = Lexer.Tokenize(testProgramStream); foreach (Token tok in tokenList) { Debug.WriteLine(tok.ToString()); Assert.NotEqual(SyntaxKind.Unknown, tok.Kind); } }
public void NoUnknownTokensInCorrectLuaFile() { TextReader testProgramStream = File.OpenText(@"CorrectSampleLuaFiles\maze.lua"); List <Token> tokenList = Lexer.Tokenize(testProgramStream); foreach (Token tok in tokenList) { Debug.WriteLine(tok.ToString()); Assert.NotEqual(SyntaxKind.Unknown, tok.Kind); } }
public async void GetLastWriteTime_DateTime_ShouldBeReturnFalseLastAccessTimeUtc(int flag, DateTime expected) { // Arrange var fileService = new FileService(); var fileName = TestValueProvider.GetValueStringByFlag(flag); // Act var result = await fileService.GetLastWriteTime(fileName); // Assert Assert.NotEqual(expected.Date, result.Date); }
public void GetGlnToUpdate_ActiveDeactivated() { // Arrange // Create fake data _sentGln.Active = false; var now = DateTime.Now; // Act var result = _glnRepository.UpdateGln(_sentGln); // Check Assert.Equal("National deactivated", result.SuspensionReason); Assert.NotEqual(now, result.SuspensionDate); }
public void TwoLanguages() { var key = new TypePromptKey(typeof(TestType).FullName, "FirstName"); _repository.Save(new CultureInfo(1033), typeof(TestType).FullName, "FirstName", "FirstName"); _repository.Save(new CultureInfo(1053), typeof(TestType).FullName, "FirstName", "Förnamn"); var enprompt = _repository.GetPrompt(new CultureInfo(1033), key); var seprompt = _repository.GetPrompt(new CultureInfo(1053), key); Assert.NotNull(enprompt); Assert.NotNull(seprompt); Assert.NotEqual(enprompt.TranslatedText, seprompt.TranslatedText); }
public async Task Edit() { var Solution = await this.Add(); var message = new HttpRequestMessage(HttpMethod.Put, API); var command = new SolutionChangeCommand { Id = Solution.Id, Name = this.GetRandom() }; message.AddJsonContent(command); var responseMessage = await this.HttpClient.SendAsync(message); await responseMessage.AsResult(); var newSolution = await this.Get(Solution.Id); Assert.NotEqual(command.Name, Solution.Name); Assert.Equal(command.Name, newSolution.Name); }
public void Map_WithTargetSubset_Success() { _tinyMapper.Bind <SourceWithSubset, TargetSubset1>(); _tinyMapper.Bind <SourceWithSubset, TargetSubset2>(); SourceWithSubset source = CreateSourceWithSubset(); var target1 = _tinyMapper.Map <TargetSubset1>(source); XAssert.Equal(default(DateTime), target1.DateTime); XAssert.Equal(source.FirstName, target1.FirstName); XAssert.Equal(source.SourceForTarget1and2, target1.LatestString); XAssert.Equal(source.SourceForTarget1, target1.SourceString); XAssert.NotEqual(source.SourceForTarget2, target1.SourceString); var target2 = _tinyMapper.Map <TargetSubset2>(source); XAssert.Equal(source.DateTime, target2.DateTime); XAssert.Equal(source.FirstName, target2.FirstName); XAssert.Equal(source.SourceForTarget1and2, target2.LatestString); XAssert.NotEqual(source.SourceForTarget1, target2.SourceString); XAssert.Equal(source.SourceForTarget2, target2.SourceString); }
public void moq() { var mock = new Mock <IDictionary <object, string> >(); var dictionary = mock.Object; mock.Setup(d => d[It.IsAny <string>()]) .Returns("a fish"); Assert.Equal("a fish", dictionary["smelt"]); Assert.Equal("a fish", dictionary["trout"]); Assert.NotEqual("a fish", dictionary[42]); mock .Setup(d => d[It.Is <string>(s => s.Last() == 's')]) .Returns("maybe plural"); mock .Setup(d => d[It.Is <string>(s => s.Last() != 's')]) .Returns("maybe singular"); Assert.Equal("maybe plural", dictionary["dogs"]); Assert.Equal("maybe singular", dictionary["trout"]); }
public void StringInequalityCaseInsensitive() { string expectedValue = "XXX"; string actualValue = "xxx"; // MSTest does not support this case. // NUnit Assert.That(actualValue, Is.Not.EqualTo(expectedValue).IgnoreCase, () => "Some context"); // Some context // Expected: not equal to "XXX", ignoring case // But was: "xxx" // XUnit does not support this case. XUnitAssert.NotEqual(expectedValue, actualValue, StringComparer.CurrentCultureIgnoreCase); // Assert.NotEqual() Failure // Expected: Not "XXX" // Actual: "xxx" // Fluent does not support this case. // Shouldly does not support this case. }
public void HasOriginalBindingContedt() { var page = new ContentPage(); var contextObject = new object(); page.BindingContext = contextObject; var behavior = new BehaviorMock { BindingContext = new object() }; page.Behaviors.Add(behavior); Assert.NotNull(behavior.BindingContext); Assert.NotEqual(contextObject, behavior.BindingContext); page.BindingContext = new object(); Assert.NotEqual(page.BindingContext, behavior.BindingContext); page.Behaviors.Clear(); Assert.Null(behavior.BindingContext); }
public void ExitOnErrorThresholdHit() { var cts = new CancellationTokenSource(10000); int attemptCount = 0; // 3 retries for each, so at least one should remain in queue. processor.PushToQueue(FakeData.New()); processor.PushToQueue(FakeData.New()); processor.PushToQueue(FakeData.New()); processor.PushToQueue(FakeData.New()); processor.Received += o => { attemptCount++; throw new Exception(); }; Assert.Throws <Exception>(() => processor.Run(cts.Token)); Assert.True(attemptCount >= 10, "attemptCount >= 10"); Assert.NotEqual(0, processor.GetQueueSize()); }
public async Task Edit() { var template = await this.Add(); var message = new HttpRequestMessage(HttpMethod.Put, API); var command = new TemplateChangeCommand { Id = template.Id, Format = this.GetConfig(), Name = this.GetRandom() }; message.AddJsonContent(command); var responseMessage = await this.HttpClient.SendAsync(message); await responseMessage.AsResult(); var newTemplate = await this.Get(template.Id); Assert.NotEqual(command.Name, template.Name); Assert.NotEqual(command.Format, template.Format); Assert.Equal(command.Name, newTemplate.Name); Assert.Equal(command.Format, newTemplate.Format); }
public async Task Edit() { var project = await this.Add(); var message = new HttpRequestMessage(HttpMethod.Put, API); var command = new ProjectChangeCommand { Id = project.Id, Name = this.GetRandom(), Version = project.Version + 1 }; message.AddJsonContent(command); var responseMessage = await this.HttpClient.SendAsync(message); await responseMessage.AsResult(); var newProject = await this.Get(project.Id); Assert.NotEqual(command.Name, project.Name); Assert.NotEqual(command.Version, project.Version); Assert.Equal(command.Name, newProject.Name); Assert.Equal(command.Version, newProject.Version); }
public static void AreNotEqual <T>(T expected, T actual, string message = null) { XAssert.NotEqual(expected, actual); }
public static void AreNotEqual(object expected, object actual, string message = null) { XAssert.NotEqual(expected, actual); }