public async Task UpdateAsync_Sets_Updated_Audit_Columns() { // arrange var scope = new DefaultScope(); const long expectedId = 12L; SaveCustomerRequest request = new SaveCustomerRequest { IndustryCodes = new List <string> { "234" }, Name = "notacustomer", SourceId = 3 }; scope.CustomerRepositoryMock.Setup(x => x.GetAsync(expectedId)).ReturnsAsync(new Customer { Id = expectedId, Updated = DateTimeOffset.MinValue, UpdatedBy = "franklin" }); scope.CustomerRepositoryMock.Setup(x => x.UpdateAsync(It.Is <Customer>( c => c.Updated > DateTimeOffset.MinValue && c.UpdatedBy == DefaultScope.UserName ))).ReturnsAsync(expectedId); // act var result = await scope.InstanceUnderTest.UpdateAsync(expectedId, request); // assert Assert.AreEqual(expectedId, result.Id); }
public async Task GetAsync_IsDeleted_Response_Returns_Null() { // arrange var scope = new DefaultScope(); const long expectedId = 12L; Customer customer = new Customer { Id = expectedId, Name = "notacustomer", SourceId = 12311, IndustryCodes = new List <string> { "12e1" }, IsDeleted = true }; scope.CustomerRepositoryMock.Setup(x => x.GetAsync(expectedId)).ReturnsAsync( customer); // act var result = await scope.InstanceUnderTest.GetAsync(expectedId); // assert Assert.IsNull(result); }
public async Task UpdateAsync_Delegates_To_Repository() { // arrange var scope = new DefaultScope(); const long expectedId = 12L; SaveCustomerRequest request = new SaveCustomerRequest { IndustryCodes = new List <string> { "234" }, Name = "notacustomer", SourceId = 3 }; scope.CustomerRepositoryMock.Setup(x => x.GetAsync(expectedId)).ReturnsAsync(new Customer { Id = expectedId }); scope.CustomerRepositoryMock.Setup(x => x.UpdateAsync(It.Is <Customer>( c => c.Id == expectedId && c.IndustryCodes.First() == request.IndustryCodes.First() && c.Name == request.Name && c.SourceId == request.SourceId ))).ReturnsAsync(expectedId); // act var result = await scope.InstanceUnderTest.UpdateAsync(expectedId, request); // assert Assert.AreEqual(expectedId, result.Id); }
public async Task UpdateCustomer_Returns_Location_If_Successful() { // arrange var scope = new DefaultScope(); var expectedId = 12L; var saveCustomerRequest = new SaveCustomerRequest() { Name = "good enough" }; var saveCustomerResponse = new SaveCustomerResponse { Id = expectedId }; scope.UpdateCustomerMock.Setup(x => x.UpdateAsync(expectedId, saveCustomerRequest)).ReturnsAsync(saveCustomerResponse); scope.SetupUrlHelper(expectedId); // act var result = await scope.InstanceUnderTest.PutAsync(expectedId, saveCustomerRequest); // assert Assert.IsTrue(result.Value.Links.First().Href.EndsWith(expectedId.ToString())); Assert.AreEqual("self", result.Value.Links.First().Rel); Assert.AreEqual("GET", result.Value.Links.First().Method); }
public void Dispose() { using (var scope = new DefaultScope()) { scope.InstanceUnderTest.Dispose(); } }
public async Task GetCustomer_Returns_Customer_If_Found() { // arrange var scope = new DefaultScope(); var expectedId = 12L; var getCustomerResponse = new GetCustomerResponse { Id = expectedId, SourceId = 123, IndustryCodes = new List <String> { "123123" }, Name = "good enough" }; scope.SetupUrlHelper(expectedId); scope.GetCustomerMock.Setup(x => x.GetAsync(expectedId)).ReturnsAsync( getCustomerResponse); // act var result = await scope.InstanceUnderTest.GetAsync(expectedId); // assert Assert.AreEqual(getCustomerResponse.Name, result.Value.Name); Assert.AreEqual(getCustomerResponse.SourceId, result.Value.SourceId); Assert.AreEqual(getCustomerResponse.IndustryCodes.First(), result.Value.IndustryCodes.First()); }
public async Task DeleteAsync_Delegates_To_Repository() { // arrange var scope = new DefaultScope(); const long expectedId = 12L; Customer customer = new Customer { Id = expectedId, Name = "notacustomer", SourceId = 12311, IndustryCodes = new List <string> { "12e1" } }; scope.CustomerRepositoryMock.Setup(x => x.GetAsync(expectedId)).ReturnsAsync( customer); scope.CustomerRepositoryMock.Setup(x => x.DeleteAsync(expectedId)).ReturnsAsync( expectedId); // act var result = await scope.InstanceUnderTest.DeleteAsync(expectedId); // assert Assert.AreEqual(customer.Id, result.Id); }
/// <summary> /// Constructor for modifying an existing item /// </summary> /// <param name="item"></param> public ModifyItemChildWindow(DefaultScope.Item item) { InitializeComponent(); this.item = ContextModel.Instance.GetItem(item); this.Loaded += new RoutedEventHandler(ItemModifyChildWindow_Loaded); }
public async Task CheckInManager_When_IdIsNull_Should_ThrowException() { // Arrange var scope = new DefaultScope(); // Act/Assert await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => scope.InstanceUnderTest.GetByIdAsync(null)); }
public void EFSharedContextFactory_Invokes_ServiceLocator_With_Expected_Args() { var scope = new DefaultScope(); var expected = scope.EFDbContextMock.Object; var actual = scope.InstanceUnderTest.Get(scope.TestEntityType, scope.TestDataSource); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); }
/// <summary> /// Construct which takes the underlying list and its associated context. /// </summary> /// <param name="list"></param> /// <param name="context"></param> public ModelList(DefaultScope.List list, ListSampleOfflineContext context) { this.list = list; this.context = context; items = null; // Register for the property changed event list.PropertyChanged += new PropertyChangedEventHandler(list_PropertyChanged); }
public void AbstractContextFactory_Create_Returns_Default_Shared_Context_Attribute_With_Undefined() { using (var scope = new DefaultScope()) { var actual = scope.InstanceUnderTest.Create <IContext>(typeof(UndefinedSharedSourceTestEntity)); Assert.IsNotNull(actual); Assert.IsInstanceOfType(actual, typeof(ITestSharedContext)); } }
public ModifyListChildWindow(DefaultScope.List scopeList) { InitializeComponent(); list = ContextModel.Instance.GetList(scopeList); NewList = true; this.Loaded += new RoutedEventHandler(NewListChildWindow_Loaded); }
public void Update(string expected) { using (var scope = new DefaultScope()) { // Arrange / Act var ex = Assert.Throws <NotImplementedException>(() => scope.InstanceUnderTest.Update(It.IsAny <MessageEntity>())); // Assert Assert.Equal(expected, ex.Message); } }
public void GetAll(string expected) { using (var scope = new DefaultScope()) { // Arrange / Act var ex = Assert.Throws <NotImplementedException>(() => scope.InstanceUnderTest.GetAll()); // Assert Assert.Equal(expected, ex.Message); } }
public async Task FoodTruckProvider_LoadData_CsvRepository_Delegates() { // arrange var scope = new DefaultScope(); // act await scope.InstanceUnderTest.LoadData(); // assert scope.CsvRepositoryMock.Verify(x => x.GetCsvData(), Times.Exactly(1)); }
public async Task FoodTruckManager_LoadData_Delegtes() { // arrange var scope = new DefaultScope(); // act await scope.InstanceUnderTest.LoadData(); // assert scope.FoodTruckProviderMock.Verify(x => x.LoadData(), Times.Exactly(1)); }
public async Task Commit_Delegates() { // Arrange var scope = new DefaultScope(); // Act await scope.InstanceUnderTest.Commit(); // Assert scope.ContextMock.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Once()); }
public async Task CheckInManager_When_GetById_Should_Return_ExpectedValue() { // Arrange var scope = new DefaultScope(); var expectedId = DefaultScope.TestEntity.Id; // Act var result = await scope.InstanceUnderTest.GetByIdAsync(expectedId); // Assert Assert.AreEqual(expectedId, result.Id); }
public async Task CheckInManager_When_GetByIdAsync_Should_Delegate_To_Repository() { // Arrange var scope = new DefaultScope(); long id = 1; // Act await scope.InstanceUnderTest.GetByIdAsync(id); // Assert scope.CheckInRepositoryMock.Verify(x => x.GetByIdAsync(It.Is <long>(v => v == id)), Times.Once); }
public async Task GetById_Delegates_To_Context() { // Arrange var scope = new DefaultScope(); var id = Guid.NewGuid(); // Act await scope.InstanceUnderTest.GetById(id); // Assert scope.ContextMock.Verify(x => x.FindAsync <MockEntity>(id, false), Times.Once()); }
public async Task Get_Does_Not_Apply_Filter() { // Arrange var scope = new DefaultScope(); // Act var results = await scope.InstanceUnderTest.Get(null, null, null); // Assert Assert.AreEqual(2, results.Count()); }
public async Task Delete_DefersCommit() { // Arrange var scope = new DefaultScope(); var entity = new MockEntity(); // Act await scope.InstanceUnderTest.Delete(entity, true); // Assert scope.ContextMock.Verify(x => x.Delete <MockEntity>(entity), Times.Once()); scope.ContextMock.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Never()); }
public void Post_Message(int response, object type) { using (var scope = new DefaultScope()) { // Arrange scope.MapperMock.Setup(x => x.Map <MessageDomainModel>(It.IsAny <MessageApiModel>())); scope.HelloWorldManagerMock.Setup(x => x.AddMessage(It.IsAny <MessageDomainModel>())).Returns(response); // Act var result = scope.InstanceUnderTest.Message(It.IsAny <MessageApiModel>()); Assert.Equal(type.GetType(), result.GetType()); } }
public async Task GetCustomer_Returns_404_If_Not_Found() { // arrange var scope = new DefaultScope(); var expectedId = 12L; scope.GetCustomerMock.Setup(x => x.GetAsync(expectedId)).ReturnsAsync(null as GetCustomerResponse); // act var result = await scope.InstanceUnderTest.GetAsync(expectedId); // assert Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult)); }
public async Task Get_Applies_Filter() { // Arrange var scope = new DefaultScope(); Expression <Func <MockEntity, bool> > filter = x => x.Id == scope.Entity1.Id; // Act var results = await scope.InstanceUnderTest.Get(filter, null, null); // Assert Assert.AreEqual(1, results.Count()); Assert.AreEqual(scope.Entity1.Id, results.FirstOrDefault().Id); }
public async Task Insert_Commits() { // Arrange var scope = new DefaultScope(); var entity = new MockEntity(); // Act await scope.InstanceUnderTest.Insert(entity, false); // Assert scope.ContextMock.Verify(x => x.Add <MockEntity>(entity), Times.Once()); scope.ContextMock.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Once()); }
public void AddMessage_NotImplementedException(MessageEntity message, int expected) { using (var scope = new DefaultScope()) { // Arrange scope.MapperMock.Setup(x => x.Map <MessageEntity>(It.IsAny <MessageDomainModel>())).Returns(message); scope.MessageRepositoryMock.Setup(x => x.Add(It.IsAny <MessageEntity>())).Throws <NotImplementedException>(); // Act var result = scope.InstanceUnderTest.AddMessage(It.IsAny <MessageDomainModel>()); // Assert Assert.Equal(expected, result); } }
public void GetMessage(AppSettingsConfig appSettings, MessageDomainModel message, string expected) { using (var scope = new DefaultScope()) { // Arrange scope.AppSettingsMock.Setup(x => x.Value).Returns(appSettings); scope.MapperMock.Setup(x => x.Map <MessageDomainModel>(It.IsAny <AppSettingsConfig>())).Returns(message); // Act var result = scope.InstanceUnderTest.GetMessage(); // Assert Assert.Equal(expected, result.Message); } }
public async Task GetAsync_Null_Response_Returns_Null() { // arrange var scope = new DefaultScope(); const long expectedId = 12L; scope.CustomerRepositoryMock.Setup(x => x.GetAsync(expectedId)).ReturnsAsync( null as Customer); // act var result = await scope.InstanceUnderTest.GetAsync(expectedId); // assert Assert.IsNull(result); }
public void Get_Message(MessageDomainModel message) { using (var scope = new DefaultScope()) { // Arrange scope.MapperMock.Setup(x => x.Map <MessageApiModel>(It.IsAny <MessageDomainModel>())); scope.HelloWorldManagerMock.Setup(x => x.GetMessage()).Returns(message); // Act var result = scope.InstanceUnderTest.Message(); // Assert Assert.IsType <OkObjectResult>(result); } }
public async Task FoodTruckProvider_LoadData_CosmosDbRepository_Delegates_Expected() { // arrange var scope = new DefaultScope(); scope.CsvRepositoryMock.Setup(x => x.GetCsvData()) .Returns(scope.TestEntities); // act await scope.InstanceUnderTest.LoadData(); // assert scope.CosmosDbRepositoryMock.Verify(x => x.UpsertItem(It.Is <TruckDetailEntity>(y => y.Id == scope.TestEntities[0].Id)), Times.Exactly(1)); scope.CosmosDbRepositoryMock.Verify(x => x.UpsertItem(It.Is <TruckDetailEntity>(y => y.Id == scope.TestEntities[1].Id)), Times.Exactly(1)); }
public void AbstractContextFactory_Skips_Clear_Dictionary_if_Null() { try { using (var scope = new DefaultScope()) { var flags = BindingFlags.Instance | BindingFlags.NonPublic; var contextCache = typeof(AbstractContextFactory).GetField("_contextCache", flags); contextCache.SetValue(scope.InstanceUnderTest, null); } } catch (NullReferenceException) { Assert.Fail("Clear was called on the context dictionary and it was not null reference protected."); } }
/// <summary> /// Deletes the specified list. /// /// NOTE: Because of the fact that the context doesn't handle referential /// integrity, the application must handle the cascading delete /// </summary> /// <param name="list"></param> public void DeleteList(DefaultScope.List list) { // First find all items that are in the list and delete them List<Item> listItems = (from i in context.ItemCollection where i.ListID == list.ID select i).ToList(); foreach (Item i in listItems) { DeleteItem(i); } // once all items are deleted, delete the list context.DeleteList(list); }
/// <summary> /// Gets the corresponding model list for a context list /// </summary> /// <param name="list"></param> /// <returns></returns> public ModelList GetList(DefaultScope.List list) { return new ModelList(list, context); }
public string CreateDocument() { IDocument document; IScope scope; using (StreamReader template = new StreamReader(new FileStream("template.html", FileMode.Open), Encoding.UTF8)) { document = new SimpleDocument(template); } scope = new DefaultScope(); scope["slideTitle"] = titleTextBox.Text; int numExts = extensionsListBox.SelectedItems.Count; var stylesheets = new Value[numExts]; var scripts = new Value[numExts]; var extSnippets = new Dictionary<Value, Value>(); int i = 0; foreach (string extName in extensionsListBox.SelectedItems) { stylesheets[i] = extensions[extName] + ".css"; scripts[i] = extensions[extName] + ".js"; var snippetName = "deck." + extName; if (snippets.ContainsKey(snippetName)) extSnippets.Add(snippetName, snippets[snippetName]); i++; } scope["extensionStylesheets"] = stylesheets; scope["extensionScripts"] = scripts; scope["extensionSnippets"] = extSnippets; scope["styleTheme"] = styles[(string)stylesListBox.SelectedItem]; scope["transitionTheme"] = transitions[(string)transitionsListBox.SelectedItem]; return document.Render(scope); }