local p=require("\078\101\120\117\115\085\110\105\116\084\101\115\116\105\110\103")local u=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107"))local L=u:GetResource("\066\097\115\101\046\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101")p:RegisterUnitTest("\067\111\110\115\116\114\117\099\116\111\114\115",function(p)local u=Instance.new("\070\114\097\109\101")u.Name="\084\101\115\116\070\114\097\109\101"local i=L.new(u)p:AssertEquals(i.ClassName,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101","\067\108\097\115\115 \110\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Name,"\084\101\115\116\070\114\097\109\101","\078\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(tostring(i),"\084\101\115\116\070\114\097\109\101","\078\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i:IsA("\070\114\097\109\101"),true,"\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \105\115\110\'\116 \097 \102\114\097\109\101\046")p:AssertEquals(i:IsA("\084\101\120\116\076\097\098\101\108"),false,"\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \105\115 \097 \084\101\120\116\076\097\098\101\108\046")p:AssertEquals(i.IsA(i,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101"),true,"\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \105\115\110\'\116 \097 \078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101\046")p:AssertEquals(i:GetWrappedInstance(),u,"\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")local o=L.GetInstance(u)local F=L.GetInstance(u)p:AssertSame(o,F,"\067\097\099\104\101\100 \119\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \110\111\116 \117\115\101\100\046")local t=L.GetInstance("\070\114\097\109\101")p:AssertEquals(t.Name,"\070\114\097\109\101","\078\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(t.BackgroundColor3,"\077\097\105\110\066\097\099\107\103\114\111\117\110\100","\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051 \105\115 \105\110\099\111\114\114\101\099\116\046")local C=Instance.new("\070\114\097\109\101")local j=L.new(C)local M=L.GetInstance(C)p:AssertSame(j,M,"\067\097\099\104\101\100 \119\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \110\111\116 \117\115\101\100\046")local f=L.new("\070\114\097\109\101")p:AssertEquals(f.Name,"\070\114\097\109\101","\078\097\109\101 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(f.BackgroundColor3,"\077\097\105\110\066\097\099\107\103\114\111\117\110\100","\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\071\097\114\098\097\103\101\067\111\108\108\101\099\116\105\111\110",function(u)local L=p.Util.DependencyInjector.Require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\078\101\120\117\115\080\108\117\103\105\110\070\114\097\109\101\119\111\114\107"))local i=L:GetResource("\066\097\115\101\046\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101")local function o()local p,u=0,0 for L,i in pairs(i.CachedInstances)do p=p+1 if L==i:GetWrappedInstance()then u=u+1 end end return p,u end local F,t=o()u:AssertEquals(F,0,"\067\097\099\104\101 \105\115 \101\109\112\116\121 \040\116\101\115\116 \105\115 \105\110\118\097\108\105\100\046\041")local C={}for p=1,10,1 do local u=Instance.new("\070\114\097\109\101")local L=i.new(u)table.insert(C,L)end local j,M=o()u:AssertEquals(j,10,"\067\097\099\104\101 \105\115 \105\110\099\111\114\114\101\099\116 \115\105\122\101\046")u:AssertEquals(M,10,"\067\097\099\104\101 \105\115 \105\110\099\111\114\114\101\099\116 \115\105\122\101\046")local f=C[1]local Y=C[2]for p=2,10,1 do C[p]:Destroy()end C={}for p=1,600,1 do local u,L=o()if u<=2 and L<=2 then break end wait(.1)end local s,Z=o()u:AssertNotNil(Y:GetWrappedInstance(),"\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \119\097\115 \103\097\114\098\097\103\101 \099\111\108\108\101\099\116\101\100\046")u:AssertEquals(s,2,"\067\097\099\104\101 \105\115 \105\110\099\111\114\114\101\099\116 \115\105\122\101 \040\071\097\114\098\097\103\101 \099\111\108\108\101\099\116\105\111\110 \109\097\121 \110\111\116 \104\097\118\101 \114\097\110\041\046")u:AssertEquals(Z,2,"\067\097\099\104\101 \105\115 \105\110\099\111\114\114\101\099\116 \115\105\122\101 \040\071\097\114\098\097\103\101 \099\111\108\108\101\099\116\105\111\110 \109\097\121 \110\111\116 \104\097\118\101 \114\097\110\041\046")u:AssertSame(i.GetInstance(f:GetWrappedInstance()),f,"\067\097\099\104\101 \111\098\106\101\099\116 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\067\104\105\108\100\114\101\110",function(p)local u,i=Instance.new("\070\114\097\109\101"),Instance.new("\070\114\097\109\101")local o,F=L.new(u),L.new(i)F.Parent=o p:AssertEquals(o.ClassName,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101","\067\108\097\115\115\078\097\109\101 \110\111\116 \099\111\114\114\101\099\116\046")p:AssertEquals(F.ClassName,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101","\067\108\097\115\115\078\097\109\101 \110\111\116 \099\111\114\114\101\099\116\046")p:AssertEquals(o.Frame.ClassName,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101","\067\108\097\115\115\078\097\109\101 \110\111\116 \099\111\114\114\101\099\116\046")p:AssertEquals((o:GetChildren())[1].ClassName,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101","\067\108\097\115\115\078\097\109\101 \110\111\116 \099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\073\110\100\101\120\080\097\115\115\116\104\114\111\117\103\104",function(p)local u=Instance.new("\070\114\097\109\101")local i=L.new(u)p:AssertEquals(i.Selectable,u.Selectable,"\083\101\108\101\099\116\097\098\108\101 \110\111\116 \112\097\115\115\101\100 \116\104\114\111\117\103\104\046")end)p:RegisterUnitTest("\082\101\112\108\105\099\097\116\105\110\103\084\111\073\110\115\116\097\110\099\101",function(p)local u=Instance.new("\070\114\097\109\101")local i=Instance.new("\070\114\097\109\101")local o,F=L.new(u),L.new(i)o.Name="\084\101\115\116\070\114\097\109\101"o.Selectable=true o.Parent=F p:AssertEquals(o.Name,"\084\101\115\116\070\114\097\109\101","\078\097\109\101 \110\111\116 \115\101\116\046")p:AssertEquals(u.Name,"\084\101\115\116\070\114\097\109\101","\078\097\109\101 \110\111\116 \114\101\112\108\105\099\097\116\101\100\046")p:AssertEquals(o.Selectable,true,"\083\101\108\101\099\116\097\098\108\101 \110\111\116 \115\101\116\046")p:AssertEquals(u.Selectable,true,"\083\101\108\101\099\116\097\098\108\101 \110\111\116 \114\101\112\108\105\099\097\116\101\100\046")p:AssertEquals(o.Parent,F,"\080\097\114\101\110\116 \110\111\116 \115\101\116\046")p:AssertEquals(u.Parent,i,"\080\097\114\101\110\116 \110\111\116 \114\101\112\108\105\099\097\116\101\100\046")o.Parent=nil p:AssertEquals(o.Parent,nil,"\080\097\114\101\110\116 \110\111\116 \117\110\115\101\116\046")p:AssertEquals(u.Parent,nil,"\080\097\114\101\110\116 \117\110\115\101\116\116\105\110\103 \110\111\116 \114\101\112\108\105\099\097\116\101\100\046")end)p:RegisterUnitTest("\082\101\112\108\105\099\097\116\105\110\103\070\114\111\109\073\110\115\116\097\110\099\101",function(p)local u,i=false,false local o=Instance.new("\070\114\097\109\101")local F=L.new(o);(F:GetPropertyChangedSignal("\078\097\109\101")):Connect(function()u=true end);(F:GetPropertyChangedSignal("\083\101\108\101\099\116\097\098\108\101")):Connect(function()i=true end)o.Name="\084\101\115\116\070\114\097\109\101"o.Selectable=true p:AssertTrue(u,"\067\104\097\110\103\101\100 \115\105\103\110\097\108 \102\111\114 \110\097\109\101 \110\111\116 \102\105\114\101\100\046")p:AssertTrue(i,"\067\104\097\110\103\101\100 \115\105\103\110\097\108 \102\111\114 \115\101\108\101\099\116\097\098\108\101 \110\111\116 \102\105\114\101\100\046")p:AssertEquals(F.Name,"\084\101\115\116\070\114\097\109\101","\078\097\109\101 \110\111\116 \115\101\116\046")p:AssertEquals(o.Name,"\084\101\115\116\070\114\097\109\101","\078\097\109\101 \110\111\116 \114\101\112\108\105\099\097\116\101\100\046")p:AssertEquals(F.Selectable,true,"\083\101\108\101\099\116\097\098\108\101 \110\111\116 \115\101\116\046")p:AssertEquals(o.Selectable,true,"\083\101\108\101\099\116\097\098\108\101 \110\111\116 \114\101\112\108\105\099\097\116\101\100\046")end)p:RegisterUnitTest("\073\110\115\116\097\110\099\101\083\116\114\117\099\116\117\114\101",function(p)local u,i=Instance.new("\070\114\097\109\101"),Instance.new("\070\114\097\109\101")local o,F=Instance.new("\070\114\097\109\101"),Instance.new("\070\114\097\109\101")local t,C=L.new(u),L.new(i)local j,M=L.new(o),L.new(F)C.Parent=t j.Parent=t M.Parent=j p:AssertEquals(u.Parent,nil,"\080\097\114\101\110\116 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(i.Parent,u,"\080\097\114\101\110\116 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(o.Parent,u,"\080\097\114\101\110\116 \105\115 \105\110\099\111\114\114\101\099\116\046")p:AssertEquals(F.Parent,o,"\080\097\114\101\110\116 \105\115 \105\110\099\111\114\114\101\099\116\046")end)p:RegisterUnitTest("\073\110\115\116\097\110\099\101\087\114\097\112\112\105\110\103",function(p)local u,i=Instance.new("\070\114\097\109\101"),Instance.new("\070\114\097\109\101")i.Parent=u local o=L.new(u)p:AssertNotNil(o.Frame,"\070\114\097\109\101 \110\111\116 \105\110\100\101\120\097\098\108\101\046")p:AssertEquals(o.Frame.ClassName,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101","\070\114\097\109\101 \110\111\116 \119\114\097\112\112\101\100\046")p:AssertNotEquals(o:__getindex("\071\101\116\067\104\105\108\100\114\101\110",nil),o.GetChildren,"\066\117\105\108\116-\105\110 \071\101\116\067\104\105\108\100\114\101\110 \109\101\116\104\111\100 \114\101\116\117\114\110\101\100 \040\117\110\105\116 \116\101\115\116 \105\110\118\097\108\105\100\041\046")p:AssertEquals(((o:__getindex("\071\101\116\067\104\105\108\100\114\101\110",nil))(o))[1].ClassName,"\078\101\120\117\115\087\114\097\112\112\101\100\073\110\115\116\097\110\099\101","\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \110\111\116 \114\101\116\117\114\110\101\100\046")end)p:RegisterUnitTest("\073\110\115\116\097\110\099\101\085\110\119\114\097\112\112\105\110\103",function(p)local u,i=Instance.new("\070\114\097\109\101"),Instance.new("\070\114\097\109\101")i.Parent=u local o,F=L.GetInstance(u),L.GetInstance(i)o.NextSelectionUp=F p:AssertEquals(u.NextSelectionUp,i,"\080\114\111\112\101\114\116\121 \110\111\116 \115\101\116\046")p:AssertNotEquals(o:__getindex("\073\115\065\110\099\101\115\116\111\114\079\102",nil),o.IsAncestorOf,"\066\117\105\108\116-\105\110 \073\115\065\110\099\101\115\116\111\114\079\102 \109\101\116\104\111\100 \114\101\116\117\114\110\101\100 \040\117\110\105\116 \116\101\115\116 \105\110\118\097\108\105\100\041\046")p:AssertTrue((o:__getindex("\073\115\065\110\099\101\115\116\111\114\079\102",nil))(o,F),"\070\114\097\109\101 \050 \105\115 \110\111\116 \097\110 \097\110\099\101\115\116\111\114 \111\102 \070\114\097\109\101 \049\046")end)p:RegisterUnitTest("\083\116\114\105\110\103\067\111\108\111\114\115",function(p)local u=Instance.new("\070\114\097\109\101")local i=L.new(u)i.BackgroundColor3=Color3.new(1,0,0)i.BorderColor3="\076\105\110\107\084\101\120\116"p:AssertClose(u.BackgroundColor3,Color3.new(1,0,0),"\067\111\108\111\114\115 \097\114\101\110\'\116 \099\108\111\115\101\046")p:AssertClose(u.BorderColor3,Color3.new(.207843,.709804,1),.001,"\067\111\108\111\114\115 \097\114\101\110\'\116 \099\108\111\115\101\046")i.BackgroundColor3=Enum.StudioStyleGuideColor.ButtonText local o=u.BackgroundColor3 i.Selected=true p:AssertNotEquals(u.BackgroundColor3,o,"\067\111\108\111\114\115 \110\111\116 \099\104\097\110\103\101\100\046")i.BackgroundColor3=Enum.StudioStyleGuideColor.ButtonText local F=u.BackgroundColor3 i.Selected=false i.Disabled=true p:AssertNotEquals(u.BackgroundColor3,F,"\067\111\108\111\114\115 \110\111\116 \099\104\097\110\103\101\100\046")i.BackgroundColor3=Enum.StudioStyleGuideColor.ButtonText local t=u.BackgroundColor3 i.Selected=true p:AssertEquals(u.BackgroundColor3,t,"\067\111\108\111\114\115 \119\097\115 \099\104\097\110\103\101\100\046")end)p:RegisterUnitTest("\067\108\111\110\101",function(p)local u,i,o=Instance.new("\070\114\097\109\101"),Instance.new("\070\114\097\109\101"),Instance.new("\070\114\097\109\101")local F,t,C=L.GetInstance(u),L.GetInstance(i),L.GetInstance(o)t.Parent=F t.NextSelectionLeft=F C.NextSelectionLeft=C C.Parent=t local j=t:Clone()p:AssertNotEquals(j:GetWrappedInstance(),i,"\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \110\111\116 \099\108\111\110\101\100\046")p:AssertNotEquals(j:FindFirstChild("\070\114\097\109\101"),o,"\067\104\105\108\100 \110\111\116 \099\108\111\110\101\100\046")p:AssertNotNil(j:FindFirstChild("\070\114\097\109\101"),"\067\104\105\108\100 \110\111\116 \099\108\111\110\101\100\046")p:AssertNotEquals((j:FindFirstChild("\070\114\097\109\101")):GetWrappedInstance(),o,"\087\114\097\112\112\101\100 \105\110\115\116\097\110\099\101 \110\111\116 \099\108\111\110\101\100\046")end)return true
--[[
TheNexusAvenger

Tests the NexusWrappedInstance class.
--]]

local NexusUnitTesting = require("NexusUnitTesting")

local NexusPluginFramework = require(game:GetService("ReplicatedStorage"):WaitForChild("NexusPluginFramework"))
local NexusWrappedInstance = NexusPluginFramework:GetResource("Base.NexusWrappedInstance")



--[[
Tests that the constructors work without failing.
--]]
NexusUnitTesting:RegisterUnitTest("Constructors",function(UnitTest)
	--Create a frame.
	local Frame1 = Instance.new("Frame")
	Frame1.Name = "TestFrame"
	
	--Create a compontent under of testing using the main constructor.
	local CuT1 = NexusWrappedInstance.new(Frame1)
	UnitTest:AssertEquals(CuT1.ClassName,"NexusWrappedInstance","Class name is incorrect.")
	UnitTest:AssertEquals(CuT1.Name,"TestFrame","Name is incorrect.")
	UnitTest:AssertEquals(tostring(CuT1),"TestFrame","Name is incorrect.")
	UnitTest:AssertEquals(CuT1:IsA("Frame"),true,"Wrapped instance isn't a frame.")
	UnitTest:AssertEquals(CuT1:IsA("TextLabel"),false,"Wrapped instance is a TextLabel.")
	UnitTest:AssertEquals(CuT1.IsA(CuT1,"NexusWrappedInstance"),true,"Wrapped instance isn't a NexusWrappedInstance.")
	UnitTest:AssertEquals(CuT1:GetWrappedInstance(),Frame1,"Wrapped instance is incorrect.")
	
	--Create 2 more components under testing from the caching builder.
	local CuT2 = NexusWrappedInstance.GetInstance(Frame1)
	local CuT3 = NexusWrappedInstance.GetInstance(Frame1)
	UnitTest:AssertSame(CuT2,CuT3,"Cached wrapped instance not used.")
	
	--Create a Frame by the string.
	local CuT4 = NexusWrappedInstance.GetInstance("Frame")
	UnitTest:AssertEquals(CuT4.Name,"Frame","Name is incorrect.")
	UnitTest:AssertEquals(CuT4.BackgroundColor3,"MainBackground","BackgroundColor3 is incorrect.")
	
	--Create 2 more components under testing from the main and caching builder.
	local Frame2 = Instance.new("Frame")
	local CuT5 = NexusWrappedInstance.new(Frame2)
	local CuT6 = NexusWrappedInstance.GetInstance(Frame2)
	UnitTest:AssertSame(CuT5,CuT6,"Cached wrapped instance not used.")
	
	--Test the main constructor with a string.
	local CuT7 = NexusWrappedInstance.new("Frame")
	UnitTest:AssertEquals(CuT7.Name,"Frame","Name is incorrect.")
	UnitTest:AssertEquals(CuT7.BackgroundColor3,"MainBackground","BackgroundColor3 is incorrect.")
end)

--[[
Tests that the wrapped instances are garbage collected.
--]]
NexusUnitTesting:RegisterUnitTest("GarbageCollection",function(UnitTest)
	--Require a new copy.
	local NexusPluginFramework = NexusUnitTesting.Util.DependencyInjector.Require(game:GetService("ReplicatedStorage"):WaitForChild("NexusPluginFramework"))
	local NexusWrappedInstance = NexusPluginFramework:GetResource("Base.NexusWrappedInstance")
	
	--[[
	Returns the amount of stored instances.
	--]]
	local function GetInstanceCount()
		local Count,CountWithReferences = 0,0
		for Ins,WrappedIns in pairs(NexusWrappedInstance.CachedInstances) do
			Count = Count + 1
			if Ins == WrappedIns:GetWrappedInstance() then
				CountWithReferences = CountWithReferences + 1
			end
		end
		
		return Count,CountWithReferences
	end
	
	--Assert nothing is cached (empty version).
	local WrappedInstanceCount,_ = GetInstanceCount()
	UnitTest:AssertEquals(WrappedInstanceCount,0,"Cache is empty (test is invalid.)")
	
	--Create and store 10 instances.
	local InstanceReferences = {}
	for i = 1,10 do
		local Ins = Instance.new("Frame")
		local WrappedIns = NexusWrappedInstance.new(Ins)
		table.insert(InstanceReferences,WrappedIns)
	end
	
	--Assert the instances are cached.
	local WrappedInstanceCount,WrappedInstanceCountWithReferences = GetInstanceCount()
	UnitTest:AssertEquals(WrappedInstanceCount,10,"Cache is incorrect size.")
	UnitTest:AssertEquals(WrappedInstanceCountWithReferences,10,"Cache is incorrect size.")
	
	--Clear the references except the first and second.
	local FirstReference = InstanceReferences[1]
	local SecondReference = InstanceReferences[2]
	for i = 2,10 do
		InstanceReferences[i]:Destroy()
	end
	InstanceReferences = {}
	
	--Wait up to 60 seconds for the cache to garbage collect.
	for i = 1,600 do
		local WrappedInstanceCount,WrappedInstanceCountWithReferences = GetInstanceCount()
		if WrappedInstanceCount <= 2 and WrappedInstanceCountWithReferences <= 2 then break end
		wait(0.1)
	end
	
	--Assert the cache was correctly garbage collected.
	local WrappedInstanceCount,WrappedInstanceCountWithReferences = GetInstanceCount()
	UnitTest:AssertNotNil(SecondReference:GetWrappedInstance(),"Wrapped instance was garbage collected.")
	UnitTest:AssertEquals(WrappedInstanceCount,2,"Cache is incorrect size (Garbage collection may not have ran).")
	UnitTest:AssertEquals(WrappedInstanceCountWithReferences,2,"Cache is incorrect size (Garbage collection may not have ran).")
	UnitTest:AssertSame(NexusWrappedInstance.GetInstance(FirstReference:GetWrappedInstance()),FirstReference,"Cache object is incorrect.")
end)

--[[
Tests adding children.
--]]
NexusUnitTesting:RegisterUnitTest("Children",function(UnitTest)
	--Create the components under testing.
	local Frame1,Frame2 = Instance.new("Frame"),Instance.new("Frame")
	local CuT1,CuT2 = NexusWrappedInstance.new(Frame1),NexusWrappedInstance.new(Frame2)
	CuT2.Parent = CuT1
	
	--Assert the class names are correct.
	UnitTest:AssertEquals(CuT1.ClassName,"NexusWrappedInstance","ClassName not correct.")
	UnitTest:AssertEquals(CuT2.ClassName,"NexusWrappedInstance","ClassName not correct.")
	UnitTest:AssertEquals(CuT1.Frame.ClassName,"NexusWrappedInstance","ClassName not correct.")
	UnitTest:AssertEquals(CuT1:GetChildren()[1].ClassName,"NexusWrappedInstance","ClassName not correct.")
end)

--[[
Tests that indexing is passed through from the wrapped instance.
--]]
NexusUnitTesting:RegisterUnitTest("IndexPassthrough",function(UnitTest)
	--Create the component under testing.
	local Frame = Instance.new("Frame")
	local CuT = NexusWrappedInstance.new(Frame)
	
	--Assert the indexes are passed through.
	UnitTest:AssertEquals(CuT.Selectable,Frame.Selectable,"Selectable not passed through.")
end)

--[[
Tests that changes are replicated to the wrapped instance.
--]]
NexusUnitTesting:RegisterUnitTest("ReplicatingToInstance",function(UnitTest)
	--Create the component under testing.
	local Frame1 = Instance.new("Frame")
	local Frame2 = Instance.new("Frame")
	local CuT1,CuT2 = NexusWrappedInstance.new(Frame1),NexusWrappedInstance.new(Frame2)
	
	--Assert the changes are passed through.
	CuT1.Name = "TestFrame"
	CuT1.Selectable = true
	CuT1.Parent = CuT2
	UnitTest:AssertEquals(CuT1.Name,"TestFrame","Name not set.")
	UnitTest:AssertEquals(Frame1.Name,"TestFrame","Name not replicated.")
	UnitTest:AssertEquals(CuT1.Selectable,true,"Selectable not set.")
	UnitTest:AssertEquals(Frame1.Selectable,true,"Selectable not replicated.")
	UnitTest:AssertEquals(CuT1.Parent,CuT2,"Parent not set.")
	UnitTest:AssertEquals(Frame1.Parent,Frame2,"Parent not replicated.")
	
	--Assert changing the parent to nil is passed through.
	CuT1.Parent = nil
	UnitTest:AssertEquals(CuT1.Parent,nil,"Parent not unset.")
	UnitTest:AssertEquals(Frame1.Parent,nil,"Parent unsetting not replicated.")
end)


--[[
Tests backwards replication for wrapped instances to the NexusWrappedInstance.
--]]
NexusUnitTesting:RegisterUnitTest("ReplicatingFromInstance",function(UnitTest)
	--Create the component under testing.
	local NameChanged,SelectableChanged = false,false
	local Frame = Instance.new("Frame")
	local CuT = NexusWrappedInstance.new(Frame)
	
	--Set up the changed events.
	CuT:GetPropertyChangedSignal("Name"):Connect(function()
		NameChanged = true
	end)
	CuT:GetPropertyChangedSignal("Selectable"):Connect(function()
		SelectableChanged = true
	end)
	
	--Change the variables.
	Frame.Name = "TestFrame"
	Frame.Selectable = true
	
	--Assert the change signals were fired.
	UnitTest:AssertTrue(NameChanged,"Changed signal for name not fired.")
	UnitTest:AssertTrue(SelectableChanged,"Changed signal for selectable not fired.")
	
	--Assert the changes are passed through.
	UnitTest:AssertEquals(CuT.Name,"TestFrame","Name not set.")
	UnitTest:AssertEquals(Frame.Name,"TestFrame","Name not replicated.")
	UnitTest:AssertEquals(CuT.Selectable,true,"Selectable not set.")
	UnitTest:AssertEquals(Frame.Selectable,true,"Selectable not replicated.")
end)


--[[
Tests that the instance structure is correct for parenting.
--]]
NexusUnitTesting:RegisterUnitTest("InstanceStructure",function(UnitTest)
	--Create 4 frames.
	local Frame1,Frame2 = Instance.new("Frame"),Instance.new("Frame")
	local Frame3,Frame4 = Instance.new("Frame"),Instance.new("Frame")
	
	--Create 4 components under testing.
	local CuT1,CuT2 = NexusWrappedInstance.new(Frame1),NexusWrappedInstance.new(Frame2)
	local CuT3,CuT4 = NexusWrappedInstance.new(Frame3),NexusWrappedInstance.new(Frame4)
	
	--Set the parents.
	CuT2.Parent = CuT1
	CuT3.Parent = CuT1
	CuT4.Parent = CuT3
	
	--Assert the parents of the frames is correct.
	UnitTest:AssertEquals(Frame1.Parent,nil,"Parent is incorrect.")
	UnitTest:AssertEquals(Frame2.Parent,Frame1,"Parent is incorrect.")
	UnitTest:AssertEquals(Frame3.Parent,Frame1,"Parent is incorrect.")
	UnitTest:AssertEquals(Frame4.Parent,Frame3,"Parent is incorrect.")
end)

--[[
Tests index wrapping from properties and functions.
--]]
NexusUnitTesting:RegisterUnitTest("InstanceWrapping",function(UnitTest)
	--Create 2 frames.
	local Frame1,Frame2 = Instance.new("Frame"),Instance.new("Frame")
	Frame2.Parent = Frame1
	
	--Create the main component under testing.
	local CuT = NexusWrappedInstance.new(Frame1)
	
	--Assert the children are index and are wrapped instances.
	UnitTest:AssertNotNil(CuT.Frame,"Frame not indexable.")
	UnitTest:AssertEquals(CuT.Frame.ClassName,"NexusWrappedInstance","Frame not wrapped.")
	
	--Assert a function returns a wrapped instance.
	UnitTest:AssertNotEquals(CuT:__getindex("GetChildren",nil),CuT.GetChildren,"Built-in GetChildren method returned (unit test invalid).")
	UnitTest:AssertEquals(CuT:__getindex("GetChildren",nil)(CuT)[1].ClassName,"NexusWrappedInstance","Wrapped instance not returned.")
end)

--[[
Tests index unwrapping to properties and functions.
--]]
NexusUnitTesting:RegisterUnitTest("InstanceUnwrapping",function(UnitTest)
	--Create 2 frames.
	local Frame1,Frame2 = Instance.new("Frame"),Instance.new("Frame")
	Frame2.Parent = Frame1
	
	--Create the components under testing.
	local CuT1,CuT2 = NexusWrappedInstance.GetInstance(Frame1),NexusWrappedInstance.GetInstance(Frame2)
	
	--Assert unwrapping an instance as a property.
	CuT1.NextSelectionUp = CuT2
	UnitTest:AssertEquals(Frame1.NextSelectionUp,Frame2,"Property not set.")
	
	--Assert unwrapping an instance as a function.
	UnitTest:AssertNotEquals(CuT1:__getindex("IsAncestorOf",nil),CuT1.IsAncestorOf,"Built-in IsAncestorOf method returned (unit test invalid).")
	UnitTest:AssertTrue(CuT1:__getindex("IsAncestorOf",nil)(CuT1,CuT2),"Frame 2 is not an ancestor of Frame 1.")
end)

--[[
Tests string Color3 propreties being set.
--]]
NexusUnitTesting:RegisterUnitTest("StringColors",function(UnitTest)
	--Create the component under testing.
	local Frame = Instance.new("Frame")
	local CuT = NexusWrappedInstance.new(Frame)
	
	--Set the colors of the border and background.
	CuT.BackgroundColor3 = Color3.new(1,0,0)
	CuT.BorderColor3 = "LinkText"
	
	--Assert the colors are correct.
	UnitTest:AssertClose(Frame.BackgroundColor3,Color3.new(1,0,0),"Colors aren't close.")
	UnitTest:AssertClose(Frame.BorderColor3,Color3.new(0.207843,0.709804,1),0.001,"Colors aren't close.")
	
	--Assert selecting the frame changes the colors.
	CuT.BackgroundColor3 = Enum.StudioStyleGuideColor.ButtonText
	local StartColor = Frame.BackgroundColor3
	CuT.Selected = true
	UnitTest:AssertNotEquals(Frame.BackgroundColor3,StartColor,"Colors not changed.")
	
	--Assert disabling the frame changes the colors.
	CuT.BackgroundColor3 = Enum.StudioStyleGuideColor.ButtonText
	local StartColor = Frame.BackgroundColor3
	CuT.Selected = false
	CuT.Disabled = true
	UnitTest:AssertNotEquals(Frame.BackgroundColor3,StartColor,"Colors not changed.")
	
	--Assert selecting the frame doesn't change the colors when disabled.
	CuT.BackgroundColor3 = Enum.StudioStyleGuideColor.ButtonText
	local StartColor = Frame.BackgroundColor3
	CuT.Selected = true
	UnitTest:AssertEquals(Frame.BackgroundColor3,StartColor,"Colors was changed.")
end)

--[[
Tests the Clone method.
--]]
NexusUnitTesting:RegisterUnitTest("Clone",function(UnitTest)
	--Create 3 frames.
	local Frame1,Frame2,Frame3 = Instance.new("Frame"),Instance.new("Frame"),Instance.new("Frame")
	
	--Create the components under testing.
	local CuT1,CuT2,CuT3 = NexusWrappedInstance.GetInstance(Frame1),NexusWrappedInstance.GetInstance(Frame2),NexusWrappedInstance.GetInstance(Frame3)
	CuT2.Parent = CuT1
	CuT2.NextSelectionLeft = CuT1
	CuT3.NextSelectionLeft = CuT3
	CuT3.Parent = CuT2
	
	--Clone the second component under testing.
	local CuT4 = CuT2:Clone()
	UnitTest:AssertNotEquals(CuT4:GetWrappedInstance(),Frame2,"Wrapped instance not cloned.")
	UnitTest:AssertNotEquals(CuT4:FindFirstChild("Frame"),Frame3,"Child not cloned.")
	UnitTest:AssertNotNil(CuT4:FindFirstChild("Frame"),"Child not cloned.")
	UnitTest:AssertNotEquals(CuT4:FindFirstChild("Frame"):GetWrappedInstance(),Frame3,"Wrapped instance not cloned.")
end)



return true