public void TestAddExchangeVisitor_SevisIdHasValue_ExceededGivenCount() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisId = "sevisId"; var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId, 1, 1); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; instance.SEVISBatchCreateUpdateEV.UpdateEV = new Business.Sevis.Model.SEVISEVBatchTypeExchangeVisitor1[2]; var previouslySubmittedExchangeVisitor = GetPreviouslySubmittedExchangeVisitor(sevisId, 1, 2); Assert.IsTrue(exchangeVisitor.GetChangeDetail(previouslySubmittedExchangeVisitor).HasChanges()); var message = "This StagedSevisBatch can not accomodate the given exchange visitor."; Action a = () => instance.AddExchangeVisitor(participant, exchangeVisitor, previouslySubmittedExchangeVisitor); a.ShouldThrow <NotSupportedException>().WithMessage(message); }
/// <summary> /// Returns true, if the given exchange visitor can be added to this batch; otherwise, false. /// </summary> /// <param name="exchangeVisitor">The exchange visitor to add.</param> /// <returns>True, if the given exchange visitor can be added to this batch; otherwise false.</returns> public bool CanAccomodate(SevisGroupedParticipantDTO participant, ExchangeVisitor exchangeVisitor, string sevisUsername, string sevisOrgId, ExchangeVisitor previouslySubmittedExchangeVisitor = null) { Contract.Requires(exchangeVisitor != null, "The exchange visitor must not be null."); Contract.Requires(participant != null, "The participant must not be null."); Contract.Requires(participant.ParticipantId == exchangeVisitor.Person.ParticipantId, "The participant must belong to the exchange visitor."); if (this.SevisUsername != sevisUsername || this.SevisOrgId != sevisOrgId) { return(false); } if (String.IsNullOrWhiteSpace(exchangeVisitor.SevisId)) { var count = this.SEVISBatchCreateUpdateEV.CreateEV == null ? 0 : this.SEVISBatchCreateUpdateEV.CreateEV.Count(); var addedItemCount = 1; return(count + addedItemCount <= this.MaxCreateExchangeVisitorRecordsPerBatch); } else { if (previouslySubmittedExchangeVisitor == null) { throw new NotSupportedException("The previously submitted exchange visitor must be supplied, since the exchange visitor has a sevis id."); } Contract.Assert(previouslySubmittedExchangeVisitor != null, "The previously submitted exchange visitor must not be null."); var count = this.SEVISBatchCreateUpdateEV.UpdateEV == null ? 0 : this.SEVISBatchCreateUpdateEV.UpdateEV.Count(); var addedItemCount = exchangeVisitor.GetSEVISEVBatchTypeExchangeVisitor1Collection(sevisUsername, previouslySubmittedExchangeVisitor).Count(); if (participant.SevisCommStatusId == SevisCommStatus.QueuedToValidate.Id) { addedItemCount += 1; } return(count + addedItemCount <= this.MaxUpdateExchangeVisitorRecordPerBatch); } }
public void TestCanAccomodate_SevisIdIsEmpty() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(string.Empty, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; Assert.IsTrue(instance.CanAccomodate(participant, exchangeVisitor, sevisUsername, sevisOrgId)); }
/// <summary> /// Adds the given exchange visitor to this batch. If this batch can not be added an exception is thrown. /// </summary> /// <param name="exchangeVisitor">The exchange visitor to add.</param> public void AddExchangeVisitor(SevisGroupedParticipantDTO participant, ExchangeVisitor exchangeVisitor, ExchangeVisitor previouslySubmittedExchangeVisitor = null) { Contract.Requires(exchangeVisitor != null, "The exchange visitor must not be null."); Contract.Requires(exchangeVisitor.Person != null, "The exchange visitor person must not be null."); Contract.Requires(participant != null, "The participant must not be null."); Contract.Requires(participant.ParticipantId == exchangeVisitor.Person.ParticipantId, "The participant must belong to the exchange visitor."); var existingExchangeVisitor = this.exchangeVisitors.Where(x => x.Person.ParticipantId == exchangeVisitor.Person.ParticipantId).FirstOrDefault(); if (existingExchangeVisitor != null) { return; } var message = "This StagedSevisBatch can not accomodate the given exchange visitor."; if (String.IsNullOrWhiteSpace(exchangeVisitor.SevisId)) { var list = this.SEVISBatchCreateUpdateEV.CreateEV != null?this.SEVISBatchCreateUpdateEV.CreateEV.ToList() : new List <SEVISEVBatchTypeExchangeVisitor>(); list.Add(exchangeVisitor.GetSEVISBatchTypeExchangeVisitor(this.SevisUsername)); this.SEVISBatchCreateUpdateEV.CreateEV = list.ToArray(); if (this.SEVISBatchCreateUpdateEV.CreateEV.Count() > this.MaxCreateExchangeVisitorRecordsPerBatch) { throw new NotSupportedException(message); } } else { if (previouslySubmittedExchangeVisitor == null) { throw new NotSupportedException("The previously submitted exchange visitor must be supplied, since the exchange visitor has a sevis id."); } Contract.Assert(previouslySubmittedExchangeVisitor != null, "The previously submitted exchange visitor must not be null."); var list = this.SEVISBatchCreateUpdateEV.UpdateEV != null?this.SEVISBatchCreateUpdateEV.UpdateEV.ToList() : new List <SEVISEVBatchTypeExchangeVisitor1>(); if (participant.SevisCommStatusId == SevisCommStatus.QueuedToValidate.Id) { list.Add(exchangeVisitor.GetSEVISEVBatchTypeExchangeVisitorValidate(this.SevisUsername)); } list.AddRange(exchangeVisitor.GetSEVISEVBatchTypeExchangeVisitor1Collection(this.SevisUsername, previouslySubmittedExchangeVisitor)); this.SEVISBatchCreateUpdateEV.UpdateEV = list.ToArray(); if (this.SEVISBatchCreateUpdateEV.UpdateEV.Count() > this.MaxUpdateExchangeVisitorRecordPerBatch) { throw new NotSupportedException(message); } } this.exchangeVisitors.Add(exchangeVisitor); }
public void TestSerializeSEVISBatchCreateUpdateEV_DoesNotHaveSevisId() { var sevisOrgId = "P-1-19833"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(null, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; Assert.IsNull(instance.SevisBatchProcessing.SendXml); instance.AddExchangeVisitor(participant, exchangeVisitor); Assert.IsNull(instance.SevisBatchProcessing.SendXml); instance.SerializeSEVISBatchCreateUpdateEV(); Assert.IsNotNull(instance.SevisBatchProcessing.SendXml); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.COMMON_NAMESPACE_PREFIX)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.TABLE_NAMESPACE_PREFIX)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.EXCHANGE_VISITOR_NAMESPACE_PREFIX)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.XSD_NAMESPACE_PREFIX)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.XSI_NAMESPACE_PREFIX)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.COMMON_NAMESPACE_URL)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.TABLE_NAMESPACE_URL)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.EXCHANGE_VISITOR_NAMESPACE_URL)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.XSD_NAMESPACE_URL)); Assert.IsTrue(instance.SevisBatchProcessing.SendString.Contains(StagedSevisBatch.XSI_NAMESPACE_URL)); //XmlReaderSettings settings = new XmlReaderSettings(); //settings.Schemas.Add("http://www.ice.gov/xmlschema/sevisbatch/alpha/Common", StagedSevisBatch.COMMON_NAMESPACE_URL); //settings.Schemas.Add("http://www.ice.gov/xmlschema/sevisbatch/alpha/Table", StagedSevisBatch.TABLE_NAMESPACE_URL); //settings.Schemas.Add("", StagedSevisBatch.EXCHANGE_VISITOR_NAMESPACE_URL); //settings.ValidationType = ValidationType.Schema; //using (XmlReader reader = XmlReader.Create(new StringReader(instance.SevisBatchProcessing.SendString), settings)) //{ // XmlDocument document = new XmlDocument(); // Action a = () => document.Load(reader); // a.ShouldNotThrow(); //} }
public void TestCanAccomodate_CreateEVArrayIsNotNull() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); instance.SEVISBatchCreateUpdateEV.CreateEV = new List <SEVISEVBatchTypeExchangeVisitor>().ToArray(); var exchangeVisitor = GetExchangeVisitor(null, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; Assert.IsTrue(instance.CanAccomodate(participant, exchangeVisitor, sevisUsername, sevisOrgId)); }
public void TestAddExchangeVisitor_SevisIdIsEmpty() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(String.Empty, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; Assert.IsNull(instance.SEVISBatchCreateUpdateEV.CreateEV); instance.AddExchangeVisitor(participant, exchangeVisitor); Assert.AreEqual(1, instance.SEVISBatchCreateUpdateEV.CreateEV.Count()); }
public void TestCanAccomodate_SevisIdHasValue_PreviouslySubmittedExchangeVisitorIsNull() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var sevisId = "sevisId"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; var expectedMessage = "The previously submitted exchange visitor must be supplied, since the exchange visitor has a sevis id."; Action a = () => instance.CanAccomodate(participant, exchangeVisitor, sevisUsername, sevisOrgId, null); a.ShouldThrow <NotSupportedException>().WithMessage(expectedMessage); }
public void TestCanAccomodate_SevisIdHasValue() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var sevisId = "sevisId"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; var previouslySubmittedExchangeVisitor = GetPreviouslySubmittedExchangeVisitor(sevisId, 1, 2); Assert.IsTrue(exchangeVisitor.GetChangeDetail(previouslySubmittedExchangeVisitor).HasChanges()); Assert.IsTrue(instance.CanAccomodate(participant, exchangeVisitor, sevisUsername, sevisOrgId, previouslySubmittedExchangeVisitor)); }
public void TestAddExchangeVisitor_SevisIdDoesNotHaveValue_ExceededDefaultCount() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(null, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; instance.SEVISBatchCreateUpdateEV.CreateEV = new Business.Sevis.Model.SEVISEVBatchTypeExchangeVisitor[StagedSevisBatch.MAX_CREATE_EXCHANGE_VISITOR_RECORDS_PER_BATCH_DEFAULT]; var message = "This StagedSevisBatch can not accomodate the given exchange visitor."; Action a = () => instance.AddExchangeVisitor(participant, exchangeVisitor); a.ShouldThrow <NotSupportedException>().WithMessage(message); }
public void TestAddExchangeVisitor_IsQueuedToValidate_ExchangeVisitorHasNotChanged() { var sevisOrgId = "org id"; var sevisId = "sevisId"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToValidate.Id, }; Assert.IsNull(instance.SEVISBatchCreateUpdateEV.CreateEV); Assert.IsFalse(exchangeVisitor.GetChangeDetail(exchangeVisitor).HasChanges()); instance.AddExchangeVisitor(participant, exchangeVisitor, exchangeVisitor); Assert.AreEqual(1, instance.SEVISBatchCreateUpdateEV.UpdateEV.Count()); }
public void TestCanAccomodate_ExchangeVisitorIsQueuedToValidate() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var sevisId = "sevisId"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); instance.SEVISBatchCreateUpdateEV.UpdateEV = new List <SEVISEVBatchTypeExchangeVisitor1>().ToArray(); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToValidate.Id, }; var previouslySubmittedExchangeVisitor = GetPreviouslySubmittedExchangeVisitor(sevisId, 1, 2); Assert.IsTrue(exchangeVisitor.GetChangeDetail(previouslySubmittedExchangeVisitor).HasChanges()); Assert.IsTrue(instance.CanAccomodate(participant, exchangeVisitor, sevisUsername, sevisOrgId, previouslySubmittedExchangeVisitor)); }
public void TestAddExchangeVisitor_SevisIdHasValue_PreviousSubmittedExchangeVisitorIsNull() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisId = "sevisId"; var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId, 1, 1); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; instance.SEVISBatchCreateUpdateEV.UpdateEV = new Business.Sevis.Model.SEVISEVBatchTypeExchangeVisitor1[2]; var message = "The previously submitted exchange visitor must be supplied, since the exchange visitor has a sevis id."; Action a = () => instance.AddExchangeVisitor(participant, exchangeVisitor, null); a.ShouldThrow <NotSupportedException>().WithMessage(message); }
public void TestAddExchangeVisitor_IsQueuedToValidate_ExceededDefaultCount() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor("sevisId", 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToValidate.Id, }; instance.SEVISBatchCreateUpdateEV.UpdateEV = new Business.Sevis.Model.SEVISEVBatchTypeExchangeVisitor1[StagedSevisBatch.MAX_UPDATE_EXCHANGE_VISITOR_RECORD_PER_BATCH_DEFAULT]; Assert.IsFalse(exchangeVisitor.GetChangeDetail(exchangeVisitor).HasChanges()); var message = "This StagedSevisBatch can not accomodate the given exchange visitor."; Action a = () => instance.AddExchangeVisitor(participant, exchangeVisitor, exchangeVisitor); a.ShouldThrow <NotSupportedException>().WithMessage(message); }
public void TestAddExchangeVisitor_ExchangeVisitorAlreadyAdded() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var sevisId = "sevisId"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; var previouslySubmittedExchangeVisitor = GetPreviouslySubmittedExchangeVisitor(sevisId, 1, 2); Assert.IsTrue(exchangeVisitor.GetChangeDetail(previouslySubmittedExchangeVisitor).HasChanges()); instance.AddExchangeVisitor(participant, exchangeVisitor, previouslySubmittedExchangeVisitor); Assert.AreEqual(1, instance.GetExchangeVisitors().Count()); instance.AddExchangeVisitor(participant, exchangeVisitor, previouslySubmittedExchangeVisitor); Assert.AreEqual(1, instance.GetExchangeVisitors().Count()); }
public void TestAddExchangeVisitor_SevisIdHasValue() { var sevisOrgId = "org id"; var batchId = BatchId.NewBatchId(); var sevisUsername = "******"; var sevisId = "sevisId"; var instance = new StagedSevisBatch(batchId, sevisUsername, sevisOrgId); var exchangeVisitor = GetExchangeVisitor(sevisId, 1, 2); var participant = new SevisGroupedParticipantDTO { ParticipantId = exchangeVisitor.Person.ParticipantId, SevisCommStatusId = SevisCommStatus.QueuedToSubmit.Id, }; Assert.IsNull(instance.SEVISBatchCreateUpdateEV.CreateEV); var previouslySubmittedExchangeVisitor = GetPreviouslySubmittedExchangeVisitor(sevisId, 1, 2); Assert.IsTrue(exchangeVisitor.GetChangeDetail(previouslySubmittedExchangeVisitor).HasChanges()); instance.AddExchangeVisitor(participant, exchangeVisitor, previouslySubmittedExchangeVisitor); Assert.AreEqual(exchangeVisitor.GetSEVISEVBatchTypeExchangeVisitor1Collection(sevisUsername, previouslySubmittedExchangeVisitor).Count(), instance.SEVISBatchCreateUpdateEV.UpdateEV.Count()); }