public void GIVEN_a_deck_with_unordered_cards_WHEN_sort_is_called_THEN_deck_is_sorted_in_order() { // Arrange var fakePack = new FakePack(); var deck = new Deck <IFakeCard>(fakePack); deck.OpenDeck(); var card1 = deck.Deal(); var card2 = deck.Deal(); var card3 = deck.Deal(); deck.AddCards(new List <IFakeCard> { card2, card1, card3 }); // Act deck.Sort(); var firstCard = deck.Deal(); var secondCard = deck.Deal(); var thirdCard = deck.Deal(); var fourthCard = deck.Deal(); // Assert Assert.AreEqual(1, firstCard.Number); Assert.AreEqual(2, secondCard.Number); Assert.AreEqual(3, thirdCard.Number); Assert.AreEqual(4, fourthCard.Number); }
private void button2_Click(object sender, EventArgs e) { string[] str = FakePack.ExamTemplate(subject, textBox1.Text, comboBox1.SelectedIndex); string[] str2 = FakePack.ExamTemplate(str); string str_l = ""; foreach (string s in str2) { if (s != null && s != "") { str_l += s + ','; } } //从*.zip到* str_l = str_l.Replace(".zip", ""); try { onlieExercise oe = new onlieExercise(this.wb, false, subject); oe.exerciseChoice = str_l; oe.worker.WorkerReportsProgress = true; oe.worker.RunWorkerAsync(); oe.Close(); } catch (Exception) { } this.Close(); }
public void GIVEN_an_unopened_deck_from_a_pack_WHEN_count_is_called_THEN_deck_not_opened_exception_thrown() { // Arrange var fakePack = new FakePack(); // Act var deck = new Deck <IFakeCard>(fakePack); var _ = deck.CardCount; }
public void GIVEN_an_unopened_deck_WHEN_deal_is_called_THEN_deck_not_opened_exception_thrown() { // Arrange var fakePack = new FakePack(); // Act var deck = new Deck <IFakeCard>(fakePack); deck.Deal(); }
public void GIVEN_an_unopened_deck_WHEN_shuffle_THEN_exception_is_thrown() { // Arrange var fakePack = new FakePack(); var fakeShuffleStrategy = new FakeShuffleStrategy(); var deck = new Deck <IFakeCard>(fakePack); // Act deck.Shuffle(fakeShuffleStrategy); }
public void GIVEN_a_deck_WHEN_shuffle_is_called_with_a_null_strategy_THEN_exception_is_thrown() { // Arrange var fakePack = new FakePack(); var deck = new Deck <IFakeCard>(fakePack); deck.OpenDeck(); // Act deck.Shuffle(null); }
public void GIVEN_a_deck_which_had_dealt_a_card_WHEN_shuffle_THEN_exception_is_thrown() { // Arrange var fakePack = new FakePack(); var fakeShuffleStrategy = new FakeShuffleStrategy(); var deck = new Deck <IFakeCard>(fakePack); deck.OpenDeck(); deck.Deal(); // Act deck.Shuffle(fakeShuffleStrategy); }
public void GIVEN_an_unopened_deck_WHEN_add_cards_is_called_with_collection_containing_a_different_type_of_card_THEN_out_of_cards_exception_is_thrown() { // Arrange var fakePack = new FakePack(); var deck = new Deck <IFakeCard>(fakePack); var cards = new List <IFakeCard> { new FakeCard(1, null), }; // Act deck.AddCards(cards); }
public void GIVEN_new_deck_WHEN_deal_is_called_THEN_top_card_is_returned() { // Arrange var fakePack = new FakePack(); var deck = new Deck <IFakeCard>(fakePack); deck.OpenDeck(); // Act var result = deck.Deal(); // Assert Assert.AreEqual("Fake1", result.Name); }
[TestMethod] public void GIVEN_new_deck_from_a_pack_WHEN_count_is_called_THEN_count_equals_number_in_pack() { // Arrange var fakePack = new FakePack(); var expectedNumberInPack = fakePack.NumberInPack; // Act var deck = new Deck <IFakeCard>(fakePack); deck.OpenDeck(); var result = deck.CardCount; // Assert Assert.AreEqual(expectedNumberInPack, result); }
public void GIVEN_a_full_deck_WHEN_shuffle_THEN_shuffle_on_shuffle_strategy_is_called() { // Arrange var fakePack = new FakePack(); var deck = new Deck <IFakeCard>(fakePack); var mockShuffleStrategy = new Mock <IShuffleStrategy <IFakeCard> >(); deck.OpenDeck(); // Act deck.Shuffle(mockShuffleStrategy.Object); // Assert mockShuffleStrategy.Verify(s => s.Shuffle(It.IsAny <IList <IFakeCard> >())); }
public void GIVEN_a_4_card_deck_WHEN_deal_is_called_5_times_THEN_out_of_cards_exception_is_thrown() { // Arrange var fakePack = new FakePack(); var deck = new Deck <IFakeCard>(fakePack); deck.OpenDeck(); // Act deck.Deal(); deck.Deal(); deck.Deal(); deck.Deal(); deck.Deal(); // Assert }
private void button1_Click(object sender, EventArgs e) { if (!FakePack.Login(subject, textBox1.Text, textBox2.Text)) { return; } string[] str = FakePack.ExamTemplate(subject, textBox1.Text); foreach (string s in str) { if (s != null && s != "") { comboBox1.Items.Add(s); } } if (comboBox1.Items.Count > 0) { comboBox1.SelectedIndex = 0; } }
public void GIVEN_a_deck_WHEN_add_cards_is_called_with_collection_THEN_cards_are_added() { // Arrange var fakePack = new FakePack(); var deck = new Deck <IFakeCard>(fakePack); deck.OpenDeck(); var cards = new List <IFakeCard> { new FakeCard(1, null), }; // Act deck.AddCards(cards); var result = deck.CardCount; // Assert Assert.AreEqual(5, result); }
public void do_work(string subj, string usr, int index) { string[] str = FakePack.ExamTemplate(subj, usr, index); string[] str2 = FakePack.ExamTemplate(str); string str_l = ""; foreach (string s in str2) { if (s != null && s != "") { str_l += s + ','; } } //从*.zip到* str_l = str_l.Replace(".zip", ""); try { string templ = str_l; BackgroundWorker th = new BackgroundWorker(); th.DoWork += delegate(object obj, DoWorkEventArgs arg) { string[] strArray = templ.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] strArray2 = null; for (int i = 0; i < strArray.Length; i++) { strArray2 = strArray[i].Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); if (!System.IO.Directory.Exists(System.IO.Directory.GetCurrentDirectory() + @"\Download")) { // 目录不存在,建立目录 System.IO.Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + @"\Download"); } FileStream stream = new FileStream("./" + "Download" + "/" + strArray[i] + ".zip", FileMode.Create); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://202.118.26.80/ChoiceSource/" + subj + "/" + strArray2[0] + "/" + strArray2[1] + "/" + strArray[i] + ".zip")); request.Method = "RETR"; request.UseBinary = true; request.Credentials = new NetworkCredential("LoginName", "Q191KPgC"); request.KeepAlive = false; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); long contentLength = response.ContentLength; int count = 0x800; byte[] buffer = new byte[count]; for (int si = responseStream.Read(buffer, 0, count); si > 0; si = responseStream.Read(buffer, 0, count)) { stream.Write(buffer, 0, si); } stream.Close(); responseStream.Close(); response.Close(); ZipHelper.Zip.Extract(Directory.GetCurrentDirectory() + "\\Download\\" + strArray[i] + ".zip", Directory.GetCurrentDirectory() + "\\Download\\", 0x400); } fatherForm.showReadyMsg(); }; th.RunWorkerCompleted += delegate(object obj2, RunWorkerCompletedEventArgs arg2) { this.Close(); }; this.Visible = false; th.RunWorkerAsync(); } catch (Exception) { } }