Ejemplo n.º 1
0
		public void CanSaveAndReadEntry()
		{
			var phoneBook = new PersistentPhoneBook(new MemoryStream());

			var expected = new Entry
			{
				FirstName = "ayende",
				LastName = "rahien",
				Number = "01231412312312",
				Type = "Home"
			};
			phoneBook.Create(expected);

			var actual = phoneBook.ReadEntries().First();

			Assert.Equal(expected, actual);
		}
Ejemplo n.º 2
0
		public void CanReadMultipleValues()
		{
			var phoneBook = new PersistentPhoneBook(new MemoryStream());

			for (int i = 0; i < 5; i++)
			{
				var expected = new Entry
				{
					FirstName = "ayende",
					LastName = "rahien",
					Number = "01231412312312",
					Type = "Home"
				};
				phoneBook.Create(expected);
			}

			Assert.Equal(5, phoneBook.ReadEntries().Count());
		}
Ejemplo n.º 3
0
		public void CanCreateAndEndEntry()
		{
			var phoneBook = new PersistentPhoneBook(new MemoryStream());

			var expected = new Entry
			{
				FirstName = "ayende",
				LastName = "rahien",
				Number = "01231412312312",
				Type = "Home"
			};
			phoneBook.Create(expected);

			var fromPhoneBook = phoneBook.ReadEntries().First();

			fromPhoneBook.LastName = "eini";
			fromPhoneBook.FirstName = "oren";

			phoneBook.Edit(fromPhoneBook);

			var fromPhoneBook2 = phoneBook.ReadEntries().First();

			Assert.Equal(fromPhoneBook, fromPhoneBook2);
		}
		public void Delete(Entry entry)
		{
			stream.Position = entry.PositionInFile;
			stream.WriteByte((byte)EntryOptions.InvalidEntryV1);
		}
		public void Edit(Entry entry)
		{
			stream.Position = entry.PositionInFile;
			WriteToStream(entry);
		}
		public void Create(Entry entry)
		{
			entry.PositionInFile = stream.Position;
			WriteToStream(entry);
		}
		private void WriteToStream(Entry entry)
		{
			stream.WriteByte((byte)EntryOptions.StandardEntryV1);
			WriteString(entry.FirstName);
			WriteString(entry.LastName);
			WriteString(entry.Number);
			WriteString(entry.Type);
		}
Ejemplo n.º 8
0
		public void OnDisposeWillCompact()
		{
			var memoryStream = new MemoryStream();
			var phoneBook = new PersistentPhoneBook(memoryStream, streamOwner:false);

			for (int i = 0; i < 5; i++)
			{
				var expected = new Entry
				{
					FirstName = "ayende",
					LastName = "rahien",
					Number = "01231412312312",
					Type = "Home"
				};
				phoneBook.Create(expected);
			}

			var before = memoryStream.Length;

			var entry = phoneBook.ReadEntries()
				.Skip(2).First();
			phoneBook.Delete(entry);

			Assert.Equal(before, memoryStream.Length); // shouldn't change

			phoneBook.Dispose();

			Assert.True(before > memoryStream.Length);

		}
Ejemplo n.º 9
0
		public void CanDeleteEntry()
		{
			var phoneBook = new PersistentPhoneBook(new MemoryStream());

			for (int i = 0; i < 5; i++)
			{
				var expected = new Entry
				{
					FirstName = "ayende",
					LastName = "rahien",
					Number = "01231412312312",
					Type = "Home"
				};
				phoneBook.Create(expected);
			}

			var entry = phoneBook.ReadEntries()
				.Skip(2).First();
			phoneBook.Delete(entry);

			Assert.Equal(4, phoneBook.ReadEntries().Count());
		}