public void PostEventDefinition_CallWebAPI_EventAdded_NotFail_Test() { int organizerId = 0; int expected = 0; var manualResetEvent = new ManualResetEvent(false); var exceptionResult = default(Exception); // Method to Test string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString(); // Get values to test using (var context = new MyEventsContext()) { organizerId = context.EventDefinitions.First().OrganizerId; expected = context.EventDefinitions.Count(q => q.OrganizerId == organizerId) + 1; } // Create object to add var eventDef = new Client.EventDefinition(); eventDef.OrganizerId = organizerId; eventDef.Name = Guid.NewGuid().ToString(); eventDef.Description = Guid.NewGuid().ToString(); eventDef.Address = Guid.NewGuid().ToString(); eventDef.City = Guid.NewGuid().ToString(); eventDef.Tags = Guid.NewGuid().ToString(); eventDef.TwitterAccount = Guid.NewGuid().ToString(); eventDef.RoomNumber = 1; eventDef.Date = System.DateTime.Now; eventDef.StartTime = System.DateTime.Now; eventDef.EndTime = System.DateTime.Now.AddDays(1); eventDef.TimeZoneOffset = 2; eventDef.Latitude = 0; eventDef.Longitude = 0; eventDef.Likes = 0; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); eventDef.Logo = encoding.GetBytes("sample"); var service = new Client.MyEventsClient(urlPrefix); service.SetAccessToken(MyEventsToken.CreateToken(eventDef.OrganizerId)); IAsyncResult ar = service.EventDefinitionService.AddEventDefinitionAsync(eventDef, (int eventDefinitionId) => { try { // Asserts using (var context = new MyEventsContext()) { Assert.IsTrue(eventDefinitionId > 0); int actual = context.EventDefinitions.Count(q => q.OrganizerId == organizerId); Assert.AreEqual(expected, actual); } } catch (Exception ex) { exceptionResult = ex; } finally { manualResetEvent.Set(); } }); TestHelper.WaitAll(manualResetEvent, ref exceptionResult); }
public void PostEventDefinition_CallWebAPI_EventAdded_NotFail_Test() { int organizerId = 0; int expected = 0; var manualResetEvent = new ManualResetEvent(false); var exceptionResult = default(Exception); // Method to Test string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString(); // Get values to test using (var context = new MyEventsContext()) { organizerId = context.EventDefinitions.First().OrganizerId; expected = context.EventDefinitions.Count(q => q.OrganizerId == organizerId) + 1; } // Create object to add var eventDef = new Client.EventDefinition(); eventDef.OrganizerId = organizerId; eventDef.Name = Guid.NewGuid().ToString(); eventDef.Description = Guid.NewGuid().ToString(); eventDef.Address = Guid.NewGuid().ToString(); eventDef.City = Guid.NewGuid().ToString(); eventDef.Tags = Guid.NewGuid().ToString(); eventDef.TwitterAccount = Guid.NewGuid().ToString(); eventDef.RoomNumber = 1; eventDef.Date = System.DateTime.Now; eventDef.StartTime = System.DateTime.Now; eventDef.EndTime = System.DateTime.Now.AddDays(1); eventDef.TimeZoneOffset = 2; eventDef.Latitude = 0; eventDef.Longitude = 0; eventDef.Likes = 0; System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); eventDef.Logo = encoding.GetBytes("sample"); var service = new Client.MyEventsClient(urlPrefix); service.SetAccessToken(MyEventsToken.CreateToken(eventDef.OrganizerId)); IAsyncResult ar = service.EventDefinitionService.AddEventDefinitionAsync(eventDef, (int eventDefinitionId) => { try { // Asserts using (var context = new MyEventsContext()) { Assert.IsTrue(eventDefinitionId > 0); int actual = context.EventDefinitions.Count(q => q.OrganizerId == organizerId); Assert.AreEqual(expected, actual); } } catch (Exception ex) { exceptionResult = ex; } finally { manualResetEvent.Set(); } }); TestHelper.WaitAll(manualResetEvent, ref exceptionResult); }