public void SearchShouldReturnSearchedTerm() { Assert.Collection( Menu.Search(Menu.CompleteMenu(), "Chicken"), (ac) => { Assert.IsType <AngryChicken>(ac); } ); }
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 RegisterWhenDataInvalid_ExpectedNotChangeBD() { //Arrange var userManager = FakeTestingService.MockUserManager <User>(_users); userManager.Setup(_ => _.CreateAsync(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Failed()); var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object); var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object); var regModel = new UserRegisterViewModel() { Address = "test", AgreementConfirm = false, Country = "test", Email = "test", FirstName = "test", Password = "******", Username = "******", Surname = "test", PasswordConfirm = "test" }; string testRedirect = "/"; //Actual var actual = await accaunt.Register(regModel, testRedirect); //Assert Assert.Equal(2, _users.Count); var model = Assert.IsType <ViewResult>(actual); Assert.IsAssignableFrom <UserRegisterViewModel>(model.ViewData.Model); }
public async Task CreatePatient_ReturnsBadRequest_GivenInvalidPatient() { string testId = string.Empty; try { testId = Test.AddTest( new testDefinition { name = "Create Patient Return Bad Request Given Invalid Patient", description = "Return a bad request if you provide a invalid Patient", storyName = "Patient Creation", featureName = "Negative Tests", epicName = "Unit Tests" }); Test.AddStep(new step { description = "Arrange", name = "Step 1: Arrange" }); // Arrange PatientController sut = this.sutBuilder.WithRepository(this.mockRepositories.Object); sut.ModelState.AddModelError("error", "some error"); Test.StopStep(Status.passed); Test.AddStep( new step { description = "Act", name = "Step 2: Act", listParamenters = new List <Parameter> { new Parameter { name = "Patient", value = null } } }); // Act var result = await sut.CreatePatient(null); Test.StopStep(Status.passed); Test.AddStep(new step { description = "Assert", name = "Step 3: Assert" }); // Assert Assert.IsType <BadRequestObjectResult>(result); Test.StopStep(Status.passed); Test.StopTest(testId, Status.passed, "Test success", "Passed"); } catch (Exception ex) { Test.StopStep(Status.failed); Test.StopTest(testId, Status.passed, "Test failed", ex.ToString()); Assert.True(false); } }
public void DeleteSuccess() { #region TestSetup var metadataFake = new Faker <MetadataInfo>() .RuleFor(m => m.Title, f => f.Lorem.Sentence()) .RuleFor(m => m.Description, f => f.Lorem.Paragraph()); var mockDefinitionFake = new Faker <MockDefinition>() .RuleFor(m => m.Host, f => f.Internet.DomainName()) .RuleFor(m => m.Metadata, f => metadataFake.Generate()); var input = new { mockDefinition = mockDefinitionFake.Generate(), httpContext = new DefaultHttpContext() }; var mediatorMock = Substitute.For <IMediator>(); mediatorMock.Send(Arg.Any <DeleteMockDefinitionByTitleCommand>(), Arg.Any <CancellationToken>()); var controllerContext = new ControllerContext() { HttpContext = input.httpContext }; #endregion var Target = new OrbitalAdminController(mediatorMock) { ControllerContext = controllerContext }; Assert.IsType <OkResult>(Target.Delete(input.mockDefinition.Metadata.Title)); }
public async Task AutheficationWhenValidData_ExpectedOKModel() { //Arrange var loginModel = new UserLoginViewModel() { Email = "*****@*****.**", Password = "", RememberMe = false }; var userManager = FakeTestingService.MockUserManager <User>(_users); userManager.Setup(m => m.FindByEmailAsync(It.IsAny <string>())) .ReturnsAsync(_users[0]); var signInManager = FakeTestingService.MockSightInManager <User>(userManager.Object); signInManager.Setup(m => m.PasswordSignInAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync(SignInResult.Success); var accaunt = new preparation.Controllers.AccountController(userManager.Object, signInManager.Object); string testRedirect = "/"; //Actual var actual = await accaunt.Login(loginModel, testRedirect); //Assert var actualVuewResult = Assert.IsType <RedirectToActionResult>(actual); }
public async Task Get_Doctor_By_Id_With_Token() { var tokenEnvironmentVariable = Environment.GetEnvironmentVariable("Token"); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenEnvironmentVariable); var httpResponseMessage = await _client.GetAsync("/api/users"); var readAsStringAsync = httpResponseMessage.Content.ReadAsStringAsync(); var result = readAsStringAsync.Result; var jArray = JArray.Parse(result); var users = jArray.ToObject <List <UserDto> >(); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenEnvironmentVariable); var defaultPage = await _client.GetAsync("/api/users/" + users[0].Id); var asStringAsync = defaultPage.Content.ReadAsStringAsync(); var json = asStringAsync.Result; var jToken = JObject.Parse(json); var user = jToken.ToObject <UserDto>(); Assert.Equal(HttpStatusCode.OK, defaultPage.StatusCode); Assert.NotNull(user); Assert.IsType <UserDto>(user); }
public void ThenTheSameFileCantBeLockedAgain() { var secondResult = new LockingController(_fakeLockingService).Lock("anotherUser", fakeFile); var secondResponse = Assert.IsType <BadRequestErrorMessageResult>(secondResult); Assert.Equal("The file is already locked", secondResponse.Message); }
public void FilterByPriceWithOnlyMinShouldReturnItemsWithDesiredPrice() { Assert.Collection( Menu.FilterByPrice(Menu.CompleteMenu(), 7, null), (rr) => { Assert.IsType <RustlersRibs>(rr); } ); }
public void FilterByPriceWithOnlyMaxShouldReturnItemsWithDesiredPrice() { Assert.Collection( Menu.FilterByPrice(Menu.CompleteMenu(), null, .5), (w) => { Assert.IsType <Water>(w); } ); }
public void FilterByCaloriesWithOnlyMaxShouldReturnItemsWithDesiredCalories() { Assert.Collection( Menu.FilterByCalories(Menu.CompleteMenu(), null, 0), (w) => { Assert.IsType <Water>(w); } ); }
public void FilterByCaloriesWithOnlyMinShouldReturnItemsWithDesiredCalories() { Assert.Collection( Menu.FilterByCalories(Menu.CompleteMenu(), 800, null), (rr) => { Assert.IsType <RustlersRibs>(rr); } ); }
public void FilterByCaloriesShouldReturnItemsWithDesiredCalories() { Assert.Collection( Menu.FilterByCalories(Menu.CompleteMenu(), 10, 100), (tt) => { Assert.IsType <TexasTea>(tt); } ); }
public static int Main(string [] args) { try { string assemblyLocation = typeof(InvalidHostingTest).Assembly.Location; string testBasePath = Path.GetDirectoryName(assemblyLocation); string componentDirectory = Path.Combine(testBasePath, $"InvalidHostingComponent_{Guid.NewGuid().ToString().Substring(0, 8)}"); Directory.CreateDirectory(componentDirectory); string componentAssemblyPath = Path.Combine(componentDirectory, "InvalidHostingComponent.dll"); File.WriteAllText(componentAssemblyPath, "Mock assembly"); object innerException = Assert.Throws <InvalidOperationException>(() => { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(testBasePath, componentAssemblyPath)); }).InnerException; Assert.IsType <DllNotFoundException>(innerException); } catch (Exception ex) { Console.WriteLine(ex); return(101); } return(100); }
public async Task SendMailWithAttachmentSucceedsAsync() { this.CallBasicModuleInit(); var response = MailModule.StartSendMail( MBTHelper.ConvertMaskedSecretToRealValue(Secrets.MAIL_SENDER_MAIL), new[] { MBTHelper.ConvertMaskedSecretToRealValue(Secrets.MAIL_RECIPIENT_MAIL_1), }, "test", "test", "<b>test</b>", new[] { "assets/favicon-32x32.png", "assets/fake_log.txt", }); var successResponse = JsonConvert.DeserializeObject <Response <string> >(response); Assert.True(!string.IsNullOrWhiteSpace(successResponse.CorrelationKey)); var messageStoreResult = await this.WaitForMessageStoreAsync(successResponse.CorrelationKey); Assert.IsType <Response <string> >(JsonConvert.DeserializeObject <Response <string> >(messageStoreResult)); }
public async Task Update_User_And_test_If_User_Changed() { var tokenEnvironmentVariable = Environment.GetEnvironmentVariable("Token"); var environmentVariable = Environment.GetEnvironmentVariable("User"); var jObject = JObject.Parse(environmentVariable); var dto = jObject.ToObject <UserDto>(); var serialize = JsonConvert.SerializeObject(dto); var content = new StringContent(serialize, Encoding.UTF8, "application/json"); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenEnvironmentVariable); var defaultPage = await _client.PutAsync("/api/users/" + dto.Id, content); var readAsStringAsync = defaultPage.Content.ReadAsStringAsync(); var json = readAsStringAsync.Result; var u = JObject.Parse(json); var user = u.ToObject <UserDto>(); var defaultPager = await _client.GetAsync("/api/users/" + user.Id); var asStringAsync = defaultPager.Content.ReadAsStringAsync(); var result = asStringAsync.Result; var parsedJObject = JObject.Parse(result); var userDto = parsedJObject.ToObject <UserDto>(); Assert.Equal(HttpStatusCode.OK, defaultPager.StatusCode); Assert.NotNull(environmentVariable); Assert.IsType <UserDto>(userDto); Assert.Equal(userDto.Name, user.Name); Assert.Equal(HttpStatusCode.OK, defaultPage.StatusCode); Assert.NotNull(user); Assert.Equal(dto.Name, user.Name); }
public async Task SearchWhenProductDoesntExist() { //Arrange var goods = new[] { new Good() { Price = 2.12m, Product = new Preparation() { Name = "_world_" } } }; var mok = new Mock <IStreinger>(); mok.Setup(m => m.Goods()) .ReturnsAsync(goods); var seachController = new preparation.Controllers.SearchController(mok.Object, null); //Actual var resp = await seachController.Search("_not_found"); //Assert var viewResult = Assert.IsType <ViewResult>(resp); var model = viewResult.ViewData.Model; Assert.Null(model); }
public void Error() { HomeController controller = new HomeController(); ViewResult result = controller.Error() as ViewResult; Assert.IsType <ViewResult>(result); }
public void GetAvailableRoomsTest() { var result = _findRoomsController.GetAvailableRooms("tenantName", 1, 1); // Assert var contentResult = Assert.IsType <ContentResult>(result); Assert.Equal("290", contentResult.Content); }
public GivenTheFilenameIsValid() { fakeFile = "aFakeFile.txt"; fakeUser = "******"; _fakeLockingService = new FakeLockingService(); lockingController = new LockingController(_fakeLockingService); result = lockingController.Lock(fakeUser, fakeFile); content = Assert.IsType <OkNegotiatedContentResult <string> >(result); }
public void BookingPurchaseTests() { var result = _findRoomsController.Bookings("tenantName", 1, 5, 100, 2, 1); var redirectToActionResult = Assert.IsType <ViewResult>(result.Result); Assert.Null(redirectToActionResult.ContentType); Assert.Equal("TenantError", redirectToActionResult.ViewName); }
public void GetAvailableSeatsTest() { var result = _findSeatsController.GetAvailableSeats(1, 1); // Assert var contentResult = Assert.IsType <ContentResult>(result); Assert.Equal("290", contentResult.Content); }
public void FindSeatsTests_BookingId_NotNull() { var result = _findRoomsController.FindRooms("tenantName", 1, 1); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <BookingModel> >(viewResult.Model); Assert.Single(model); }
public void FindSeatsTests_BookingId_Null() { var result = _findRoomsController.FindRooms("tenantName", 0, 1); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.NotNull(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); Assert.Equal("Bookings", redirectToActionResult.ControllerName); }
public void FindSeatsTests_EventId_Null() { var result = _findSeatsController.FindSeats(0); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.NotNull(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); Assert.Equal("Events", redirectToActionResult.ControllerName); }
public void FindSeatsTests_EventId_NotNull() { var result = _findSeatsController.FindSeats(1); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <EventModel> >(viewResult.Model); Assert.Equal(1, model.Count()); }
public void PurchaseTicketsTests() { var result = _findSeatsController.PurchaseTickets(1, 5, 100, 2, 1); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.NotNull(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); Assert.Equal("Events", redirectToActionResult.ControllerName); }
public void BookingPurchaseTests() { var result = _findRoomsController.PurchaseTickets("tenantName", 1, 5, 100, 2, 1); var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.NotNull(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); Assert.Equal("Bookings", redirectToActionResult.ControllerName); }
public void RegisterCustomerTest() { //Act var result = _accountController.Register("tenantName", GetCustomer()); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); }